- require 'rubygems'
- require 'sequel'
- require 'lib/jdbc/noarch-ncluster-jdbc-driver.jar'
- module Sequel
- class Dataset
- def quote_schema_table(table)
- schema, table = schema_and_table(table)
- "#{"#{schema}." if schema}#{table}"
- end
- end
- class Database
- def quote_schema_table(table)
- schema, table = schema_and_table(table)
- "#{"#{schema}." if schema}#{table}"
- end
- def create_fact_table(name, options={}, &block)
- options[:fact] = true
- create_table(name, options, &block)
- end
- def create_dimension_table(name, options={}, &block)
- options[:dimension] = true
- create_table(name, options, &block)
- end
- def unquoted_schema_table(table)
- schema, table = schema_and_table(table)
- "#{"#{schema}." if schema}#{table}"
- end
- def create_table_sql(name, generator, options)
- if options[:fact]
- "CREATE FACT TABLE #{unquoted_schema_table(name)} (#{column_list_sql(generator)}, PARTITION KEY (\"#{options[:partition_key].to_s.upcase}\") )"
- elsif options[:dimension]
- puts "CREATE DIMENSION TABLE #{unquoted_schema_table(name)} (#{column_list_sql(generator)}) "
- "CREATE DIMENSION TABLE #{unquoted_schema_table(name)} (#{column_list_sql(generator)}) "
- else
- "CREATE #{temporary_table_sql if options[:temp]}TABLE #{quote_schema_table(name)} (#{column_list_sql(generator)}) "
- end
- end
- end
- end
- DB_HOST = ""
- DB_NAME = ""
- DB_USER = ""
- DB_PASSWORD = ""
- connection_string = "jdbc:ncluster://%s/%s?user=%s&password=%s" % [DB_HOST,DB_NAME,DB_USER,DB_PASSWORD]
- db = Sequel.connect(connection_string)
- if db[:raw_file__demo_demo]
- db.drop_table(:raw_file__demo_demo)
- end
- db.create_dimension_table(:raw_file__demo_demo) do |table|
- String :foo
- String :bar
- end
- demo_demo = db[:raw_file__demo_demo]
- puts db.schema(:raw_file__demo_demo)
- demo_demo.insert(:foo => "WTF", :bar => "HELLO")
- oak-dw-qaetl2.yourmomz.com:/home/dwuser/data_warehouse/etl/UPS_Downloader> jruby test_jdbc.rb
- CREATE DIMENSION TABLE raw_file.demo_demo ("FOO" varchar(255), "BAR" varchar(255))
- foo
- typestringdb_typecharacter varying(255)defaultallow_nulltrueprimary_keyfalsecolumn_size255scale0ruby_default
- bar
- typestringdb_typecharacter varying(255)defaultallow_nulltrueprimary_keyfalsecolumn_size255scale0ruby_default
- com/asterdata/ncluster/core/v3/QueryExecutorImpl.java:2007:in `receiveErrorResponse': NativeException: com.asterdata.ncluster.util.NClusterException: ERROR: relation "RAW_FILE"."DEMO_DEMO" does not \
- exist (Sequel::DatabaseError)
- from com/asterdata/ncluster/core/v3/QueryExecutorImpl.java:1734:in `processResults'
- from com/asterdata/ncluster/core/v3/QueryExecutorImpl.java:281:in `execute'
- from com/asterdata/ncluster/jdbc2/AbstractJdbc2Statement.java:453:in `execute'
- from com/asterdata/ncluster/jdbc2/AbstractJdbc2Statement.java:338:in `executeWithFlags'
- from com/asterdata/ncluster/jdbc2/AbstractJdbc2Statement.java:284:in `executeUpdate'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/jdbc.rb:197:in `execute'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/database/logging.rb:23:in `log_yield'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/jdbc.rb:196:in `execute'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/jdbc.rb:441:in `statement'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/jdbc.rb:188:in `execute'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/connection_pool/threaded.rb:84:in `hold'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/database/connecting.rb:189:in `synchronize'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/jdbc.rb:187:in `execute'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/jdbc.rb:222:in `execute_insert'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/dataset/actions.rb:408:in `execute_insert'
- from /opt/local/jruby-1.5.0/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/dataset/actions.rb:207:in `insert'
- from test_jdbc.rb:67