Class: Iceberg::TableDefinition
- Inherits:
-
Object
- Object
- Iceberg::TableDefinition
- Defined in:
- lib/iceberg/table_definition.rb
Constant Summary collapse
- TYPES =
%w[ boolean int long float double decimal date time timestamp timestamptz timestamp_nano timestamptz_nano string uuid fixed binary ]
- TYPE_ALIASES =
{ "integer" => "int", "bigint" => "long" }
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #column(name, type, null: true, default: nil, comment: nil, limit: nil, precision: nil, scale: nil) ⇒ Object
-
#initialize ⇒ TableDefinition
constructor
A new instance of TableDefinition.
Constructor Details
#initialize ⇒ TableDefinition
Returns a new instance of TableDefinition.
16 17 18 |
# File 'lib/iceberg/table_definition.rb', line 16 def initialize @fields = [] end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
14 15 16 |
# File 'lib/iceberg/table_definition.rb', line 14 def fields @fields end |
Instance Method Details
#column(name, type, null: true, default: nil, comment: nil, limit: nil, precision: nil, scale: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/iceberg/table_definition.rb', line 26 def column(name, type, null: true, default: nil, comment: nil, limit: nil, precision: nil, scale: nil) unless type.is_a?(Type) type = type.to_s type = case TYPE_ALIASES.fetch(type, type) when "boolean" BooleanType.new when "int" IntType.new when "long" LongType.new when "float" FloatType.new when "double" DoubleType.new when "decimal" DecimalType.new(precision, scale) when "date" DateType.new when "time" TimeType.new when "timestamp" TimestampType.new when "timestamptz" TimestamptzType.new when "timestamp_nano" TimestampNanoType.new when "timestamptz_nano" TimestamptzNanoType.new when "string" StringType.new when "uuid" UUIDType.new when "fixed" FixedType.new(limit) when "binary" BinaryType.new else type end end @fields << NestedField.new( field_id: @fields.size + 1, name: name.to_s, field_type: type, required: !null, doc: comment, # no need for initial default (and not supported until v3) write_default: default ) end |