Sha256: e36f1b143bd0057646a3f87b7d29a9122a460d36d5156df4ac222a04a2dcda71
Contents?: true
Size: 1.88 KB
Versions: 13
Compression:
Stored size: 1.88 KB
Contents
Feature: Import a CSV file into the database with a split transformation Scenario: Successful import Given a database table called "dim_product" with the following fields: | field_name | field_type | | item | TEXT | | title | TEXT | | category1 | TEXT | | category2 | TEXT | | category3 | TEXT | And a "products.csv" data file containing: """ id,name,category JNI-123,Just a product name,Main category > Subcategory > Sub-subcategory > Ultra-subcategory CDI-234,Another product name,Smart Insight > Cool stuff | 3dim > 2dim > 1dim """ And the following definition: """ source :products do encoding "UTF-8" delimiter ',' field :id, String field :name, String field :category, String end source :transformed_products do field :id, String field :name, String field :main_category, String field :sub_category, String field :department, String end transform :products => :transformed_products do |record| record.split_field :category, into: [:category], by: "|" record.split_field :category, into: [:main_category, :sub_category, :department], by: ">" output record end import :transformed_products do into :dim_product put :id => :item put :name => :title put :main_category => :category1 put :sub_category => :category2 put :department => :category3 end """ When I execute the definition Then the process should exit successfully And the "dim_product" table should contain: | item | title | category1 | category2 | category3 | | JNI-123 | Just a product name | Main category | Subcategory | Sub-subcategory | | CDI-234 | Another product name | Smart Insight | Cool stuff | Cool stuff |
Version data entries
13 entries across 13 versions & 1 rubygems