Module: Flydata::Redshift::Util
- Included in:
- Mysql::RedshiftTableAdapter
- Defined in:
- lib/flydata/command/sync.rb
Constant Summary collapse
- MAX_TABLENAME_LENGTH =
127
- REDSHIFT_RESERVED_WORDS =
%w[ aes128 aes256 all allowoverwrite analyse analyze and any array as asc authorization backup between binary blanksasnull both bytedict case cast check collate column constraint create credentials cross current_date current_time current_timestamp current_user current_user_id default deferrable deflate defrag delta delta32k desc disable distinct do else emptyasnull enable encode encrypt encryption end except explicit false for foreign freeze from full globaldict256 globaldict64k grant group gzip having identity ignore ilike in initially inner intersect into is isnull join leading left like limit localtime localtimestamp lun luns minus mostly13 mostly32 mostly8 natural new not notnull null nulls off offline offset old on only open or order outer overlaps parallel partition percent placing primary raw readratio recover references rejectlog resort restore right select session_user similar some sysdate system table tag tdes text255 text32k then to top trailing true truncatecolumns union unique user using verbose wallet when where with without]
- REDSHIFT_RESERVED_WORDS_HASH =
Create a symbol-keyed hash for performance
REDSHIFT_RESERVED_WORDS.inject({}) {|h, word| h[word.to_sym] = true; h}
- REDSHIFT_SYSTEM_COLUMNS =
%w[oid tableoid xmin cmin xmax cmax ctid]
- REDSHIFT_SYSTEM_COLUMNS_HASH =
REDSHIFT_SYSTEM_COLUMNS.inject({}) {|h, word| h[word.to_sym] = true; h}
Instance Method Summary collapse
- #convert_to_valid_name(key, type = :table) ⇒ Object
- #is_redshift_reserved_word?(name, type = :table) ⇒ Boolean
Instance Method Details
#convert_to_valid_name(key, type = :table) ⇒ Object
673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/flydata/command/sync.rb', line 673 def convert_to_valid_name(key, type = :table) @memo ||= { table:{}, column:{} } key_sym = key.to_sym return @memo[type][key_sym] if @memo[type][key_sym] name = key.downcase.gsub(/[^a-z0-9_$]/, '_') name = "_#{name}" if is_redshift_reserved_word?(name, type) or name =~ /^[0-9$]/ if name.length > MAX_TABLENAME_LENGTH name = nil end @memo[key_sym] = name name end |
#is_redshift_reserved_word?(name, type = :table) ⇒ Boolean
687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'lib/flydata/command/sync.rb', line 687 def is_redshift_reserved_word?(name, type = :table) return false unless name return true if REDSHIFT_RESERVED_WORDS_HASH[name.to_sym] == true case type when :table false when :column REDSHIFT_SYSTEM_COLUMNS_HASH[name.to_sym] == true else false end end |