diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/arrow/ruby/red-gandiva/lib | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/arrow/ruby/red-gandiva/lib')
20 files changed, 787 insertions, 0 deletions
diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva.rb b/src/arrow/ruby/red-gandiva/lib/gandiva.rb new file mode 100644 index 000000000..6a47a3210 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva.rb @@ -0,0 +1,29 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "arrow" + +require "gandiva/version" + +require "gandiva/loader" + +module Gandiva + class Error < StandardError + end + + Loader.load +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/arrow-schema.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/arrow-schema.rb new file mode 100644 index 000000000..1656b4736 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/arrow-schema.rb @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Arrow + class Schema + def build_expression(&block) + builder = Gandiva::ExpressionBuilder.new(self) + builder.build(&block) + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder.rb new file mode 100644 index 000000000..405a1f68e --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder.rb @@ -0,0 +1,45 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + class ExpressionBuilder + def initialize(schema) + @schema = schema + end + + def build + builder = yield(Record.new(@schema), Context.new) + node = builder.build + Expression.new(node, + Arrow::Field.new("result", node.return_type)) + end + end +end + +require "gandiva/expression-builder/add" +require "gandiva/expression-builder/context" +require "gandiva/expression-builder/divide" +require "gandiva/expression-builder/elsif" +require "gandiva/expression-builder/equal" +require "gandiva/expression-builder/field" +require "gandiva/expression-builder/greater-than" +require "gandiva/expression-builder/if" +require "gandiva/expression-builder/literal" +require "gandiva/expression-builder/less-than" +require "gandiva/expression-builder/multiply" +require "gandiva/expression-builder/record" +require "gandiva/expression-builder/subtract" diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/add.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/add.rb new file mode 100644 index 000000000..210d47d52 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/add.rb @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/binary-operation" + +module Gandiva + class ExpressionBuilder + class Add < BinaryOperation + def initialize(left, right) + super("add", left, right) + end + + private + def return_type(left_node, right_node) + # TODO: More clever implementation. e.g. (int64, float) -> float + left_return_type = left_node.return_type + right_return_type = right_node.return_type + if left_return_type.bit_width > right_return_type.bit_width + left_return_type + else + right_return_type + end + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/binary-operation.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/binary-operation.rb new file mode 100644 index 000000000..922bdc4f3 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/binary-operation.rb @@ -0,0 +1,38 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/value" + +module Gandiva + class ExpressionBuilder + class BinaryOperation < Value + def initialize(operator, left, right) + @operator = operator + @left = left + @right = right + end + + def build + left_node = @left.build + right_node = @right.build + FunctionNode.new(@operator, + [left_node, right_node], + return_type(left_node, right_node)) + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/context.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/context.rb new file mode 100644 index 000000000..25ceee5d0 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/context.rb @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + class ExpressionBuilder + class Context + def if(condition) + If.new(condition) + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/divide.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/divide.rb new file mode 100644 index 000000000..9888dc2a0 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/divide.rb @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/binary-operation" + +module Gandiva + class ExpressionBuilder + class Divide < BinaryOperation + def initialize(left, right) + super("divide", left, right) + end + + private + def return_type(left_node, right_node) + # TODO: Use float if left or right is float + left_node.return_type + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/elsif.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/elsif.rb new file mode 100644 index 000000000..f5fc086d9 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/elsif.rb @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/if" + +module Gandiva + class ExpressionBuilder + class Elsif < If + def initialize(parent, condition) + @parent = parent + super(condition) + end + + def build + elsif_node = super + build_if_node(@parent.condition_node, + @parent.then_node, + elsif_node) + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/equal.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/equal.rb new file mode 100644 index 000000000..3e3ec2580 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/equal.rb @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/binary-operation" + +module Gandiva + class ExpressionBuilder + class Equal < BinaryOperation + def initialize(left, right) + super("equal", left, right) + end + + private + def return_type(left_node, right_node) + Arrow::BooleanDataType.new + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/field.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/field.rb new file mode 100644 index 000000000..916333e23 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/field.rb @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/value" + +module Gandiva + class ExpressionBuilder + class Field < Value + def initialize(field) + @field = field + end + + def build + FieldNode.new(@field) + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/greater-than.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/greater-than.rb new file mode 100644 index 000000000..65d146f9e --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/greater-than.rb @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/binary-operation" + +module Gandiva + class ExpressionBuilder + class GreaterThan < BinaryOperation + def initialize(left, right) + super("greater_than", left, right) + end + + private + def return_type(left_node, right_node) + Arrow::BooleanDataType.new + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/if.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/if.rb new file mode 100644 index 000000000..c0a00c3a8 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/if.rb @@ -0,0 +1,75 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + class ExpressionBuilder + class If + def initialize(condition) + @condition = condition + @then = nil + @else = nil + end + + def then(clause) + @then = clause + self + end + + def else(clause) + @else = clause + self + end + + def elsif(condition) + Elsif.new(self, condition) + end + + def build + build_if_node(condition_node, + then_node, + else_node) + end + + protected + def condition_node + @condition.build + end + + def then_node + @then&.build + end + + def else_node + @else&.build + end + + private + def build_if_node(condition_node, then_node, else_node) + if then_node and else_node + # TODO: Validate then_node.return_type == else_node.return_type + return_type = then_node.return_type + else + return_type = (then_node || else_node).return_type + end + IfNode.new(condition_node, + then_node, + else_node, + return_type) + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/less-than.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/less-than.rb new file mode 100644 index 000000000..93d19abd1 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/less-than.rb @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/binary-operation" + +module Gandiva + class ExpressionBuilder + class LessThan < BinaryOperation + def initialize(left, right) + super("less_than", left, right) + end + + private + def return_type(left_node, right_node) + Arrow::BooleanDataType.new + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/literal.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/literal.rb new file mode 100644 index 000000000..da2de8273 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/literal.rb @@ -0,0 +1,65 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + class ExpressionBuilder + class Literal + class << self + def resolve(value) + case value + when true, false + new(BooleanLiteralNode, value) + when Integer + if value < -(2 ** 31) + new(Int64LiteralNode, value) + elsif value < -(2 ** 15) + new(Int32LiteralNode, value) + elsif value < -(2 ** 7) + new(Int16LiteralNode, value) + elsif value < 0 + new(Int8LiteralNode, value) + elsif value < (2 ** 8 - 1) + new(UInt8LiteralNode, value) + elsif value < (2 ** 16 - 1) + new(UInt16LiteralNode, value) + elsif value < (2 ** 32 - 1) + new(UInt32LiteralNode, value) + else + new(UInt64LiteralNode, value) + end + when Float + new(DoubleLiteralNode, value) + when String + new(StringLiteralNode, value) + else + nil + end + end + end + + attr_reader :value + def initialize(node_class, value) + @node_class = node_class + @value = value + end + + def build + @node_class.new(value) + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/multiply.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/multiply.rb new file mode 100644 index 000000000..55c57a55d --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/multiply.rb @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/binary-operation" + +module Gandiva + class ExpressionBuilder + class Multiply < BinaryOperation + def initialize(left, right) + super("multiply", left, right) + end + + private + def return_type(left_node, right_node) + # TODO: Use larger type + right_node.return_type + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/record.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/record.rb new file mode 100644 index 000000000..a8cd124fc --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/record.rb @@ -0,0 +1,45 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + class ExpressionBuilder + class Record + def initialize(schema) + @schema = schema + end + + def respond_to_missing?(name, include_private) + return true if @schema[name] + super + end + + def method_missing(name, *args) + return super unless args.empty? + self[name] || super + end + + def [](name) + field = @schema[name] + if field + Field.new(field) + else + nil + end + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/subtract.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/subtract.rb new file mode 100644 index 000000000..cc3810b72 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/subtract.rb @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require "gandiva/expression-builder/binary-operation" + +module Gandiva + class ExpressionBuilder + class Subtract < BinaryOperation + def initialize(left, right) + super("subtract", left, right) + end + + private + def return_type(left_node, right_node) + # TODO: Use larger type + right_node.return_type + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/value.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/value.rb new file mode 100644 index 000000000..366e08871 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/expression-builder/value.rb @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + class ExpressionBuilder + class Value + def +(right) + Add.new(self, resolve(right)) + end + + def -(right) + Subtract.new(self, resolve(right)) + end + + def *(right) + Multiply.new(self, resolve(right)) + end + + def /(right) + Divide.new(self, resolve(right)) + end + + def >(right) + GreaterThan.new(self, resolve(right)) + end + + def <(right) + LessThan.new(self, resolve(right)) + end + + def ==(right) + Equal.new(self, resolve(right)) + end + + private + def resolve(value) + Literal.resolve(value) or value + end + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/loader.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/loader.rb new file mode 100644 index 000000000..2d8c8a713 --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/loader.rb @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + class Loader < GObjectIntrospection::Loader + class << self + def load + super("Gandiva", Gandiva) + end + end + + private + def load_method_info(info, klass, method_name) + case klass.name + when "Gandiva::BooleanLiteralNode" + case method_name + when "value?" + method_name = "value" + end + super(info, klass, method_name) + else + super + end + end + + def post_load(repository, namespace) + require_libraries + end + + def require_libraries + require "gandiva/arrow-schema" + require "gandiva/expression-builder" + end + end +end diff --git a/src/arrow/ruby/red-gandiva/lib/gandiva/version.rb b/src/arrow/ruby/red-gandiva/lib/gandiva/version.rb new file mode 100644 index 000000000..c78f165ec --- /dev/null +++ b/src/arrow/ruby/red-gandiva/lib/gandiva/version.rb @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +module Gandiva + VERSION = "6.0.1" + + module Version + numbers, TAG = VERSION.split("-") + MAJOR, MINOR, MICRO = numbers.split(".").collect(&:to_i) + STRING = VERSION + end +end |