require 'flydata/table_meta' require 'flydata-core/postgresql/pg_client' require 'flydata-core/postgresql/snapshot' require 'flydata-core/table_def/postgresql_table_def' module Flydata module SourcePostgresql # Fetch and keep table meta information # # : # table_name: # Table name # table_schema: or nil # Schema name # primary_keys: # Set primary key names. ex: ['group_id', 'category_id'] # pk_positions: # Set the ordinal position of primary keys. ex: [1, 3] # max_row_size: # byte, calculated based on column size # max_num_rows_per_query>: # max number of rows per query # raw_columns: # raw information schema data # columns: table_def.columns # table_def: # columns: # table: # column: # type: # not_null: # primary_key: # default: # column_size: (new) # Set in `PostgresqlTableDef.parse_one_column_def` # class TableMeta < Flydata::TableMeta GET_TABLE_META_SQL = <][:raw_columns] columns.each do |col| column_name = col['column_name'].to_sym table_name = col['table_name'].to_sym t_meta = ret[table_name] t_meta[:raw_columns] ||= {} t_meta[:raw_columns][column_name] = col end ret.each do |table_name, t_meta| begin table_def = FlydataCore::TableDef::PostgresqlTableDef.create( t_meta[:raw_columns].values, :skip_primary_key_check) rescue FlydataCore::TableDefError => e t_meta.merge!( table_name: table_name, table_def_err: e, ) # Skip when getting an error when parsing the columns next end primary_keys = [] pk_positions = [] table_def.columns.each.with_index(1) do |col, index| col_name = col[:column] if col[:primary_key] primary_keys << col_name pk_positions << index.to_s end end t_meta.merge!( table_name: table_name.to_s, table_schema: @schema, primary_keys: primary_keys, pk_positions: pk_positions, #max_row_size: max_row_size, #TODO: calculation #max_num_rows_per_query: max_row_size + 128, #TODO: calculation max_num_rows_per_query: DEFAULT_MAX_FETCH_RECORD_SIZE, columns: table_def.columns, table_def: table_def, ) end ret end def calc_column_size(column) #TODO: Implement the check logic based on column type 124 end end end end