[Groonga-commit] groonga/groonga at c9b8fe6 [master] expr optimize: add support for assign and ref

Back to archive index
Kouhei Sutou null+****@clear*****
Mon Mar 4 12:22:58 JST 2019


Kouhei Sutou	2019-03-04 12:22:58 +0900 (Mon, 04 Mar 2019)

  Revision: c9b8fe61938a5ea6b0abefe7e65d4298ceda0447
  https://github.com/groonga/groonga/commit/c9b8fe61938a5ea6b0abefe7e65d4298ceda0447

  Message:
    expr optimize: add support for assign and ref

  Added files:
    lib/mrb/scripts/expression_tree/assign.rb
    lib/mrb/scripts/expression_tree/reference.rb
  Modified files:
    lib/mrb/scripts/expression_tree.rb
    lib/mrb/scripts/expression_tree/sources.am
    lib/mrb/scripts/expression_tree_builder.rb

  Modified: lib/mrb/scripts/expression_tree.rb (+2 -0)
===================================================================
--- lib/mrb/scripts/expression_tree.rb    2019-03-04 12:13:31 +0900 (f789f7a81)
+++ lib/mrb/scripts/expression_tree.rb    2019-03-04 12:22:58 +0900 (f27a4457e)
@@ -1,10 +1,12 @@
 require "expression_tree/accessor"
+require "expression_tree/assign"
 require "expression_tree/binary_operation"
 require "expression_tree/constant"
 require "expression_tree/function_call"
 require "expression_tree/index_column"
 require "expression_tree/logical_operation"
 require "expression_tree/procedure"
+require "expression_tree/reference"
 require "expression_tree/table"
 require "expression_tree/unary_operation"
 require "expression_tree/variable"

  Added: lib/mrb/scripts/expression_tree/assign.rb (+18 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/expression_tree/assign.rb    2019-03-04 12:22:58 +0900 (beb43dec5)
@@ -0,0 +1,18 @@
+module Groonga
+  module ExpressionTree
+    class Assign
+      attr_reader :variable
+      attr_reader :value
+      def initialize(variable, value)
+        @variable = variable
+        @value = value
+      end
+
+      def build(expression)
+        @variable.build(expression)
+        @value.build(expression)
+        expression.append_operator(Operator::ASSIGN, 2)
+      end
+    end
+  end
+end

  Added: lib/mrb/scripts/expression_tree/reference.rb (+18 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/expression_tree/reference.rb    2019-03-04 12:22:58 +0900 (ccee16b1d)
@@ -0,0 +1,18 @@
+module Groonga
+  module ExpressionTree
+    class Reference
+      attr_reader :column
+      def initialize(column)
+        @column = column
+      end
+
+      def build(expression)
+        expression.append_object(@column, Operator::GET_REF, 1)
+      end
+
+      def estimate_size(table)
+        table.size
+      end
+    end
+  end
+end

  Modified: lib/mrb/scripts/expression_tree/sources.am (+2 -0)
===================================================================
--- lib/mrb/scripts/expression_tree/sources.am    2019-03-04 12:13:31 +0900 (0bfb385f4)
+++ lib/mrb/scripts/expression_tree/sources.am    2019-03-04 12:22:58 +0900 (d5269d111)
@@ -1,11 +1,13 @@
 RUBY_SCRIPT_FILES =				\
 	accessor.rb				\
+	assign.rb				\
 	binary_operation.rb			\
 	constant.rb				\
 	function_call.rb			\
 	index_column.rb				\
 	logical_operation.rb			\
 	procedure.rb				\
+	reference.rb				\
 	table.rb				\
 	unary_operation.rb			\
 	variable.rb

  Modified: lib/mrb/scripts/expression_tree_builder.rb (+8 -0)
===================================================================
--- lib/mrb/scripts/expression_tree_builder.rb    2019-03-04 12:13:31 +0900 (ca0190b0b)
+++ lib/mrb/scripts/expression_tree_builder.rb    2019-03-04 12:22:58 +0900 (f708d60c5)
@@ -83,9 +83,17 @@ module Groonga
           value = stack.pop
           node = ExpressionTree::UnaryOperation.new(code.op, value)
           stack.push(node)
+        when Operator::GET_REF
+          node = ExpressionTree::Reference.new(code.value)
+          stack.push(node)
         when Operator::GET_VALUE
           node = ExpressionTree::Variable.new(code.value)
           stack.push(node)
+        when Operator::ASSIGN
+          value = stack.pop
+          variable = stack.pop
+          node = ExpressionTree::Assign.new(variable, value)
+          stack.push(node)
         when Operator::PUSH
           case code.value
           when Procedure
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190304/e0f6aa43/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index