diff --git a/lib/rasti/db/nql/nodes/comparisons/base.rb b/lib/rasti/db/nql/nodes/comparisons/base.rb index 370f740..7114bae 100644 --- a/lib/rasti/db/nql/nodes/comparisons/base.rb +++ b/lib/rasti/db/nql/nodes/comparisons/base.rb @@ -6,7 +6,7 @@ module Comparisons class Base < Treetop::Runtime::SyntaxNode def dependency_tables - left.tables.empty? ? [] : [left.tables.join('.')] + field.tables.empty? ? [] : [field.tables.join('.')] end end diff --git a/lib/rasti/db/nql/nodes/comparisons/equal.rb b/lib/rasti/db/nql/nodes/comparisons/equal.rb index 0feeba4..83c3819 100644 --- a/lib/rasti/db/nql/nodes/comparisons/equal.rb +++ b/lib/rasti/db/nql/nodes/comparisons/equal.rb @@ -6,7 +6,7 @@ module Comparisons class Equal < Base def to_filter - { left.to_filter => right.value } + { field.identifier => argument.value } end end diff --git a/lib/rasti/db/nql/nodes/comparisons/greater_than.rb b/lib/rasti/db/nql/nodes/comparisons/greater_than.rb index 324bc17..e8e915c 100644 --- a/lib/rasti/db/nql/nodes/comparisons/greater_than.rb +++ b/lib/rasti/db/nql/nodes/comparisons/greater_than.rb @@ -6,7 +6,7 @@ module Comparisons class GreaterThan < Base def to_filter - left.to_filter > right.value + field.identifier > argument.value end end diff --git a/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb b/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb index daea6e8..f512811 100644 --- a/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb +++ b/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb @@ -6,7 +6,7 @@ module Comparisons class GreaterThanOrEqual < Base def to_filter - left.to_filter >= right.value + field.identifier >= argument.value end end diff --git a/lib/rasti/db/nql/nodes/comparisons/include.rb b/lib/rasti/db/nql/nodes/comparisons/include.rb index b60bc14..f9ec51b 100644 --- a/lib/rasti/db/nql/nodes/comparisons/include.rb +++ b/lib/rasti/db/nql/nodes/comparisons/include.rb @@ -6,7 +6,7 @@ module Comparisons class Include < Base def to_filter - Sequel.ilike(left.to_filter, "%#{right.value}%") + Sequel.ilike(field.identifier, "%#{argument.value}%") end end diff --git a/lib/rasti/db/nql/nodes/comparisons/less_than.rb b/lib/rasti/db/nql/nodes/comparisons/less_than.rb index c0a6ead..243508b 100644 --- a/lib/rasti/db/nql/nodes/comparisons/less_than.rb +++ b/lib/rasti/db/nql/nodes/comparisons/less_than.rb @@ -6,7 +6,7 @@ module Comparisons class LessThan < Base def to_filter - left.to_filter < right.value + field.identifier < argument.value end end diff --git a/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb b/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb index 59c1089..ae85f46 100644 --- a/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb +++ b/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb @@ -6,7 +6,7 @@ module Comparisons class LessThanOrEqual < Base def to_filter - left.to_filter <= right.value + field.identifier <= argument.value end end diff --git a/lib/rasti/db/nql/nodes/comparisons/like.rb b/lib/rasti/db/nql/nodes/comparisons/like.rb index cc0797e..c43bf37 100644 --- a/lib/rasti/db/nql/nodes/comparisons/like.rb +++ b/lib/rasti/db/nql/nodes/comparisons/like.rb @@ -6,7 +6,7 @@ module Comparisons class Like < Base def to_filter - Sequel.ilike(left.to_filter, right.value) + Sequel.ilike(field.identifier, argument.value) end end diff --git a/lib/rasti/db/nql/nodes/comparisons/not_equal.rb b/lib/rasti/db/nql/nodes/comparisons/not_equal.rb index 3128129..1953a0d 100644 --- a/lib/rasti/db/nql/nodes/comparisons/not_equal.rb +++ b/lib/rasti/db/nql/nodes/comparisons/not_equal.rb @@ -6,7 +6,7 @@ module Comparisons class NotEqual < Base def to_filter - Sequel.negate(left.to_filter => right.value) + Sequel.negate(field.identifier => argument.value) end end diff --git a/lib/rasti/db/nql/nodes/comparisons/not_include.rb b/lib/rasti/db/nql/nodes/comparisons/not_include.rb index 2898569..c884b95 100644 --- a/lib/rasti/db/nql/nodes/comparisons/not_include.rb +++ b/lib/rasti/db/nql/nodes/comparisons/not_include.rb @@ -6,7 +6,7 @@ module Comparisons class NotInclude < Base def to_filter - ~ Sequel.ilike(left.to_filter, "%#{right.value}%") + ~ Sequel.ilike(field.identifier, "%#{argument.value}%") end end diff --git a/lib/rasti/db/nql/nodes/field.rb b/lib/rasti/db/nql/nodes/field.rb index a517e38..ff722dc 100644 --- a/lib/rasti/db/nql/nodes/field.rb +++ b/lib/rasti/db/nql/nodes/field.rb @@ -4,7 +4,7 @@ module NQL module Nodes class Field < Treetop::Runtime::SyntaxNode - def to_filter + def identifier tables.empty? ? Sequel[column.to_sym] : Sequel[tables.join('__').to_sym][column.to_sym] end diff --git a/lib/rasti/db/nql/syntax.rb b/lib/rasti/db/nql/syntax.rb index da2459a..3912b2f 100644 --- a/lib/rasti/db/nql/syntax.rb +++ b/lib/rasti/db/nql/syntax.rb @@ -510,7 +510,7 @@ def _nt_field end module ComparisonInclude0 - def left + def field elements[0] end @@ -518,7 +518,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -591,7 +591,7 @@ def _nt_comparison_include end module ComparisonNotInclude0 - def left + def field elements[0] end @@ -599,7 +599,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -672,7 +672,7 @@ def _nt_comparison_not_include end module ComparisonLike0 - def left + def field elements[0] end @@ -680,7 +680,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -753,7 +753,7 @@ def _nt_comparison_like end module ComparisonGreaterThan0 - def left + def field elements[0] end @@ -761,7 +761,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -834,7 +834,7 @@ def _nt_comparison_greater_than end module ComparisonGreaterThanOrEqual0 - def left + def field elements[0] end @@ -842,7 +842,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -915,7 +915,7 @@ def _nt_comparison_greater_than_or_equal end module ComparisonLessThan0 - def left + def field elements[0] end @@ -923,7 +923,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -996,7 +996,7 @@ def _nt_comparison_less_than end module ComparisonLessThanOrEqual0 - def left + def field elements[0] end @@ -1004,7 +1004,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -1077,7 +1077,7 @@ def _nt_comparison_less_than_or_equal end module ComparisonNotEqual0 - def left + def field elements[0] end @@ -1085,7 +1085,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end @@ -1158,7 +1158,7 @@ def _nt_comparison_not_equal end module ComparisonEqual0 - def left + def field elements[0] end @@ -1166,7 +1166,7 @@ def comparator elements[2] end - def right + def argument elements[4] end end diff --git a/lib/rasti/db/nql/syntax.treetop b/lib/rasti/db/nql/syntax.treetop index ddcd6ac..025ecfd 100644 --- a/lib/rasti/db/nql/syntax.treetop +++ b/lib/rasti/db/nql/syntax.treetop @@ -47,39 +47,39 @@ module Rasti end rule comparison_include - left:field space* comparator:':' space* right:basic + field:field space* comparator:':' space* argument:basic end rule comparison_not_include - left:field space* comparator:'!:' space* right:basic + field:field space* comparator:'!:' space* argument:basic end rule comparison_like - left:field space* comparator:'~' space* right:basic + field:field space* comparator:'~' space* argument:basic end rule comparison_greater_than - left:field space* comparator:'>' space* right:basic + field:field space* comparator:'>' space* argument:basic end rule comparison_greater_than_or_equal - left:field space* comparator:'>=' space* right:basic + field:field space* comparator:'>=' space* argument:basic end rule comparison_less_than - left:field space* comparator:'<' space* right:basic + field:field space* comparator:'<' space* argument:basic end rule comparison_less_than_or_equal - left:field space* comparator:'<=' space* right:basic + field:field space* comparator:'<=' space* argument:basic end rule comparison_not_equal - left:field space* comparator:'!=' space* right:basic + field:field space* comparator:'!=' space* argument:basic end rule comparison_equal - left:field space* comparator:'=' space* right:basic + field:field space* comparator:'=' space* argument:basic end rule basic diff --git a/spec/nql/syntax_parser_spec.rb b/spec/nql/syntax_parser_spec.rb index 0424cd5..adb3c4d 100644 --- a/spec/nql/syntax_parser_spec.rb +++ b/spec/nql/syntax_parser_spec.rb @@ -31,8 +31,8 @@ def parse(expression) proposition = tree.proposition proposition.must_be_instance_of node_class proposition.comparator.text_value.must_equal comparator - proposition.left.text_value.must_equal 'column' - proposition.right.text_value.must_equal 'value' + proposition.field.text_value.must_equal 'column' + proposition.argument.text_value.must_equal 'value' end end @@ -44,8 +44,8 @@ def parse(expression) proposition = tree.proposition proposition.must_be_instance_of Rasti::DB::NQL::Nodes::Comparisons::Equal proposition.comparator.text_value.must_equal '=' - proposition.left.text_value.must_equal 'column' - proposition.right.text_value.must_equal 'value' + proposition.field.text_value.must_equal 'column' + proposition.argument.text_value.must_equal 'value' end describe 'Right hand Operand' do @@ -53,7 +53,7 @@ def parse(expression) it 'must parse expression with integer' do tree = parse 'column = 1' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::Integer right_hand_operand.value.must_equal 1 end @@ -61,7 +61,7 @@ def parse(expression) it 'must parse expression with float' do tree = parse 'column = 2.3' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::Float right_hand_operand.value.must_equal 2.3 end @@ -69,7 +69,7 @@ def parse(expression) it 'must parse expression with true' do tree = parse 'column = true' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::True right_hand_operand.value.must_equal true end @@ -77,7 +77,7 @@ def parse(expression) it 'must parse expression with false' do tree = parse 'column = false' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::False right_hand_operand.value.must_equal false end @@ -85,7 +85,7 @@ def parse(expression) it 'must parse expression with string' do tree = parse 'column = String1 ' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::String right_hand_operand.value.must_equal 'String1' end @@ -93,7 +93,7 @@ def parse(expression) it 'must parse expression with literal string' do tree = parse 'column = "a & (b | c) | d:=e"' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::LiteralString right_hand_operand.value.must_equal 'a & (b | c) | d:=e' end @@ -103,7 +103,7 @@ def parse(expression) it 'must parse expression with hours and minutes' do tree = parse 'column > 12:20' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::Time right_hand_operand.value.must_equal Timing::TimeInZone.parse('12:20').to_s end @@ -111,7 +111,7 @@ def parse(expression) it 'must parse expression with date, hours, minutes and seconds' do tree = parse 'column > 2019-03-27T12:20:00' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::Time right_hand_operand.value.must_equal Timing::TimeInZone.parse('2019-03-27T12:20:00').to_s end @@ -119,7 +119,7 @@ def parse(expression) it 'must parse expression with date, hours, minutes, seconds and timezone' do tree = parse 'column > 2019-03-27T12:20:00-03:00' - right_hand_operand = tree.proposition.right + right_hand_operand = tree.proposition.argument right_hand_operand.must_be_instance_of Rasti::DB::NQL::Nodes::Constants::Time right_hand_operand.value.must_equal Timing::TimeInZone.parse('2019-03-27T12:20:00-03:00').to_s end @@ -131,7 +131,7 @@ def parse(expression) it 'must parse expression with field with tables' do tree = parse 'relation_table_one.relation_table_two.column = 1' - left_hand_operand = tree.proposition.left + left_hand_operand = tree.proposition.field left_hand_operand.tables.must_equal ['relation_table_one', 'relation_table_two'] left_hand_operand.column.must_equal 'column' end