Class: YbDDLParser::AST::ParseResult
- Inherits:
-
Data
- Object
- Data
- YbDDLParser::AST::ParseResult
- Defined in:
- lib/yb_ddl_parser/ast.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
Class Method Summary collapse
- .build_statement(hash) ⇒ Object
- .column(hash) ⇒ Object
- .command(hash) ⇒ Object
- .constraint(hash) ⇒ Object
- .diagnostic(hash) ⇒ Object
- .from_hash(hash) ⇒ Object
- .key_column(hash) ⇒ Object
- .partition_spec(hash) ⇒ Object
- .relation(hash) ⇒ Object
- .sym(value) ⇒ Object
- .tablet_split(hash) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors
128 129 130 |
# File 'lib/yb_ddl_parser/ast.rb', line 128 def errors @errors end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements
128 129 130 |
# File 'lib/yb_ddl_parser/ast.rb', line 128 def statements @statements end |
Class Method Details
.build_statement(hash) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/yb_ddl_parser/ast.rb', line 159 def self.build_statement(hash) Statement.new( kind: sym(hash[:kind]), raw_node_type: hash[:raw_node_type], sql: hash[:sql], location: hash[:location], relation: relation(hash[:relation]), object_type: sym(hash[:object_type]), objects: Array(hash[:objects]).map { |obj| relation(obj) }, columns: Array(hash[:columns]).map { |col| column(col) }, constraints: Array(hash[:constraints]).map { |constraint_hash| constraint(constraint_hash) }, primary_key: hash[:primary_key] && constraint(hash[:primary_key]), commands: Array(hash[:commands]).map { |cmd| command(cmd) }, index_name: hash[:index_name], unique: hash[:unique], concurrently: sym(hash[:concurrently]), access_method: hash[:access_method], keys: Array(hash[:keys]).map { |key| key_column(key) }, include_columns: Array(hash[:include_columns]), where_sql: hash[:where_sql], tablespace: hash[:tablespace], tablet_split: tablet_split(hash[:split]), partition_spec: partition_spec(hash[:partition]), partition_of: relation(hash[:partition_of]), partition_bound_sql: hash[:partition_bound_sql], if_exists: hash[:if_exists], if_not_exists: hash[:if_not_exists], name: hash[:name], owner: hash[:owner], new_name: hash[:new_name], tablespace_location: hash[:tablespace_location], replica_placement_json: hash[:replica_placement_json], ) end |
.column(hash) ⇒ Object
231 232 233 234 235 236 237 238 |
# File 'lib/yb_ddl_parser/ast.rb', line 231 def self.column(hash) Column.new( name: hash[:name], type: hash[:type], typmods: Array(hash[:typmods]), constraints: Array(hash[:constraints]).map { |constraint_hash| constraint(constraint_hash) }, ) end |
.command(hash) ⇒ Object
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/yb_ddl_parser/ast.rb', line 220 def self.command(hash) Command.new( kind: sym(hash[:kind]), column: hash[:column] && column(hash[:column]), definition: hash[:definition], constraint: hash[:constraint] && constraint(hash[:constraint]), tablespace: hash[:tablespace], missing_ok: hash[:missing_ok], ) end |
.constraint(hash) ⇒ Object
240 241 242 243 244 245 246 247 248 249 |
# File 'lib/yb_ddl_parser/ast.rb', line 240 def self.constraint(hash) Constraint.new( type: sym(hash[:type]), name: hash[:name], columns: Array(hash[:columns]), key_columns: Array(hash[:key_columns]).map { |key| key_column(key) }, raw_expression: hash[:raw_expression], functions: Array(hash[:functions]), ) end |
.diagnostic(hash) ⇒ Object
194 195 196 197 198 199 |
# File 'lib/yb_ddl_parser/ast.rb', line 194 def self.diagnostic(hash) ParseDiagnostic.new( message: hash[:message], position: hash[:position], ) end |
.from_hash(hash) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/yb_ddl_parser/ast.rb', line 129 def self.from_hash(hash) new( statements: Array(hash[:statements]).map { |stmt| build_statement(stmt) }, errors: Array(hash[:errors]).map { |error| diagnostic(error) }, ) end |
.key_column(hash) ⇒ Object
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/yb_ddl_parser/ast.rb', line 251 def self.key_column(hash) KeyColumn.new( name: hash[:name], expression: hash[:expression], order: sym(hash[:order]), nulls: sym(hash[:nulls]), hashed: hash[:hash], hash_group: hash[:hash_group], ) end |
.partition_spec(hash) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/yb_ddl_parser/ast.rb', line 211 def self.partition_spec(hash) return unless hash PartitionSpec.new( strategy: sym(hash[:strategy]), keys: Array(hash[:keys]), ) end |
.relation(hash) ⇒ Object
262 263 264 265 266 |
# File 'lib/yb_ddl_parser/ast.rb', line 262 def self.relation(hash) return unless hash RelationName.new(schema: hash[:schema], name: hash[:name]) end |
.sym(value) ⇒ Object
268 269 270 |
# File 'lib/yb_ddl_parser/ast.rb', line 268 def self.sym(value) value.nil? ? nil : value.to_sym end |
.tablet_split(hash) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/yb_ddl_parser/ast.rb', line 201 def self.tablet_split(hash) return unless hash TabletSplit.new( type: sym(hash[:type]), num_tablets: hash[:num_tablets], points: hash[:points], ) end |
Instance Method Details
#each_column ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/yb_ddl_parser/ast.rb', line 148 def each_column return enum_for(:each_column) unless block_given? statements.each do |stmt| stmt.columns.each { |column| yield column, stmt } if stmt.columns stmt.commands.each do |cmd| yield cmd.column, stmt if cmd.column end if stmt.commands end end |
#each_statement(&block) ⇒ Object
144 145 146 |
# File 'lib/yb_ddl_parser/ast.rb', line 144 def each_statement(&block) statements.each(&block) end |
#single_statement! ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/yb_ddl_parser/ast.rb', line 136 def single_statement! if statements.length != 1 raise ParseError, "expected exactly one statement, got #{statements.length}" end statements.first end |