]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/InNode.java
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org
.apache
.arrow
.gandiva
.expression
;
20 import java
.math
.BigDecimal
;
21 import java
.nio
.charset
.Charset
;
24 import org
.apache
.arrow
.gandiva
.exceptions
.GandivaException
;
25 import org
.apache
.arrow
.gandiva
.ipc
.GandivaTypes
;
27 import com
.google
.protobuf
.ByteString
;
30 * In Node representation in java.
32 public class InNode
implements TreeNode
{
33 private static final Charset charset
= Charset
.forName("UTF-8");
35 private final Set
<Integer
> intValues
;
36 private final Set
<Long
> longValues
;
37 private final Set
<Float
> floatValues
;
38 private final Set
<Double
> doubleValues
;
39 private final Set
<BigDecimal
> decimalValues
;
40 private final Set
<String
> stringValues
;
41 private final Set
<byte[]> binaryValues
;
42 private final TreeNode input
;
44 private final Integer precision
;
45 private final Integer scale
;
47 private InNode(Set
<Integer
> values
, Set
<Long
> longValues
, Set
<String
> stringValues
, Set
<byte[]>
48 binaryValues
, Set
<BigDecimal
> decimalValues
, Integer precision
, Integer scale
,
49 Set
<Float
> floatValues
, Set
<Double
> doubleValues
, TreeNode node
) {
50 this.intValues
= values
;
51 this.longValues
= longValues
;
52 this.decimalValues
= decimalValues
;
53 this.precision
= precision
;
55 this.stringValues
= stringValues
;
56 this.binaryValues
= binaryValues
;
57 this.floatValues
= floatValues
;
58 this.doubleValues
= doubleValues
;
63 * Makes an IN node for int values.
65 * @param node Node with the 'IN' clause.
66 * @param intValues Int values to build the IN node.
67 * @retur InNode referring to tree node.
69 public static InNode
makeIntInExpr(TreeNode node
, Set
<Integer
> intValues
) {
70 return new InNode(intValues
,
71 null, null, null, null, null, null, null,
76 * Makes an IN node for long values.
78 * @param node Node with the 'IN' clause.
79 * @param longValues Long values to build the IN node.
80 * @retur InNode referring to tree node.
82 public static InNode
makeLongInExpr(TreeNode node
, Set
<Long
> longValues
) {
83 return new InNode(null, longValues
,
84 null, null, null, null, null, null,
89 * Makes an IN node for float values.
91 * @param node Node with the 'IN' clause.
92 * @param floatValues Float values to build the IN node.
93 * @retur InNode referring to tree node.
95 public static InNode
makeFloatInExpr(TreeNode node
, Set
<Float
> floatValues
) {
96 return new InNode(null, null, null, null, null, null,
97 null, floatValues
, null, node
);
101 * Makes an IN node for double values.
103 * @param node Node with the 'IN' clause.
104 * @param doubleValues Double values to build the IN node.
105 * @retur InNode referring to tree node.
107 public static InNode
makeDoubleInExpr(TreeNode node
, Set
<Double
> doubleValues
) {
108 return new InNode(null, null, null, null, null,
109 null, null, null, doubleValues
, node
);
112 public static InNode
makeDecimalInExpr(TreeNode node
, Set
<BigDecimal
> decimalValues
,
113 Integer precision
, Integer scale
) {
114 return new InNode(null, null, null, null,
115 decimalValues
, precision
, scale
, null, null, node
);
118 public static InNode
makeStringInExpr(TreeNode node
, Set
<String
> stringValues
) {
119 return new InNode(null, null, stringValues
, null,
120 null, null, null, null, null, node
);
123 public static InNode
makeBinaryInExpr(TreeNode node
, Set
<byte[]> binaryValues
) {
124 return new InNode(null, null, null, binaryValues
,
125 null, null, null, null, null, node
);
129 public GandivaTypes
.TreeNode
toProtobuf() throws GandivaException
{
130 GandivaTypes
.InNode
.Builder inNode
= GandivaTypes
.InNode
.newBuilder();
132 inNode
.setNode(input
.toProtobuf());
134 if (intValues
!= null) {
135 GandivaTypes
.IntConstants
.Builder intConstants
= GandivaTypes
.IntConstants
.newBuilder();
136 intValues
.stream().forEach(val
-> intConstants
.addIntValues(GandivaTypes
.IntNode
.newBuilder()
137 .setValue(val
).build()));
138 inNode
.setIntValues(intConstants
.build());
139 } else if (longValues
!= null) {
140 GandivaTypes
.LongConstants
.Builder longConstants
= GandivaTypes
.LongConstants
.newBuilder();
141 longValues
.stream().forEach(val
-> longConstants
.addLongValues(GandivaTypes
.LongNode
.newBuilder()
142 .setValue(val
).build()));
143 inNode
.setLongValues(longConstants
.build());
144 } else if (floatValues
!= null) {
145 GandivaTypes
.FloatConstants
.Builder floatConstants
= GandivaTypes
.FloatConstants
.newBuilder();
146 floatValues
.stream().forEach(val
-> floatConstants
.addFloatValues(GandivaTypes
.FloatNode
.newBuilder()
147 .setValue(val
).build()));
148 inNode
.setFloatValues(floatConstants
.build());
149 } else if (doubleValues
!= null) {
150 GandivaTypes
.DoubleConstants
.Builder doubleConstants
= GandivaTypes
.DoubleConstants
.newBuilder();
151 doubleValues
.stream().forEach(val
-> doubleConstants
.addDoubleValues(GandivaTypes
.DoubleNode
.newBuilder()
152 .setValue(val
).build()));
153 inNode
.setDoubleValues(doubleConstants
.build());
154 } else if (decimalValues
!= null) {
155 GandivaTypes
.DecimalConstants
.Builder decimalConstants
= GandivaTypes
.DecimalConstants
.newBuilder();
156 decimalValues
.stream().forEach(val
-> decimalConstants
.addDecimalValues(GandivaTypes
.DecimalNode
.newBuilder()
157 .setValue(val
.toPlainString()).setPrecision(precision
).setScale(scale
).build()));
158 inNode
.setDecimalValues(decimalConstants
.build());
159 } else if (stringValues
!= null) {
160 GandivaTypes
.StringConstants
.Builder stringConstants
= GandivaTypes
.StringConstants
162 stringValues
.stream().forEach(val
-> stringConstants
.addStringValues(GandivaTypes
.StringNode
163 .newBuilder().setValue(ByteString
.copyFrom(val
.getBytes(charset
))).build()));
164 inNode
.setStringValues(stringConstants
.build());
165 } else if (binaryValues
!= null) {
166 GandivaTypes
.BinaryConstants
.Builder binaryConstants
= GandivaTypes
.BinaryConstants
168 binaryValues
.stream().forEach(val
-> binaryConstants
.addBinaryValues(GandivaTypes
.BinaryNode
169 .newBuilder().setValue(ByteString
.copyFrom(val
)).build()));
170 inNode
.setBinaryValues(binaryConstants
.build());
172 GandivaTypes
.TreeNode
.Builder builder
= GandivaTypes
.TreeNode
.newBuilder();
173 builder
.setInNode(inNode
.build());
174 return builder
.build();