2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.apache.hadoop.hive.ql.exec.vector.expressions.gen;
21 import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
22 import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
23 import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
24 import org.apache.hadoop.hive.ql.exec.vector.expressions.NullUtil;
25 import org.apache.hadoop.hive.ql.exec.vector.expressions.DecimalUtil;
26 import org.apache.hadoop.hive.ql.exec.vector.VectorExpressionDescriptor;
27 import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
28 import org.apache.hadoop.hive.common.type.HiveDecimal;
31 * Generated from template ScalarDivideColumnDecimal.txt, which covers binary arithmetic
32 * expressions between a scalar and a column.
34 public class <ClassName> extends VectorExpression {
36 private static final long serialVersionUID = 1L;
39 private HiveDecimal value;
40 private int outputColumn;
42 public <ClassName>(HiveDecimal value, int colNum, int outputColumn) {
45 this.outputColumn = outputColumn;
46 this.outputType = "decimal";
49 public <ClassName>() {
50 this.outputType = "decimal";
54 public void evaluate(VectorizedRowBatch batch) {
56 if (childExpressions != null) {
57 super.evaluateChildren(batch);
60 DecimalColumnVector inputColVector = (DecimalColumnVector) batch.cols[colNum];
61 DecimalColumnVector outputColVector = (DecimalColumnVector) batch.cols[outputColumn];
62 int[] sel = batch.selected;
63 boolean[] inputIsNull = inputColVector.isNull;
64 boolean[] outputIsNull = outputColVector.isNull;
65 outputColVector.noNulls = inputColVector.noNulls;
66 outputColVector.isRepeating = inputColVector.isRepeating;
68 HiveDecimalWritable[] vector = inputColVector.vector;
69 HiveDecimalWritable[] outputVector = outputColVector.vector;
71 // return immediately if batch is empty
76 if (inputColVector.noNulls) {
78 /* Initialize output vector NULL values to false. This is necessary
79 * since the decimal operation may produce a NULL result even for
80 * a non-null input vector value, and convert the output vector
81 * to have noNulls = false;
83 NullUtil.initOutputNullsToFalse(outputColVector, inputColVector.isRepeating,
84 batch.selectedInUse, sel, n);
87 if (inputColVector.isRepeating) {
88 DecimalUtil.<Operator>Checked(0, value, vector[0], outputColVector);
90 // Even if there are no nulls, we always copy over entry 0. Simplifies code.
91 outputIsNull[0] = inputIsNull[0];
92 } else if (inputColVector.noNulls) {
93 if (batch.selectedInUse) {
94 for(int j = 0; j != n; j++) {
96 DecimalUtil.<Operator>Checked(i, value, vector[i], outputColVector);
99 for(int i = 0; i != n; i++) {
100 DecimalUtil.<Operator>Checked(i, value, vector[i], outputColVector);
103 } else /* there are nulls */ {
104 if (batch.selectedInUse) {
105 for(int j = 0; j != n; j++) {
108 // copy isNull entry first because the operation may overwrite it
109 outputIsNull[i] = inputIsNull[i];
110 DecimalUtil.<Operator>Checked(i, value, vector[i], outputColVector);
114 // copy isNull entries first because the operation may overwrite them
115 System.arraycopy(inputIsNull, 0, outputIsNull, 0, n);
116 for(int i = 0; i != n; i++) {
117 DecimalUtil.<Operator>Checked(i, value, vector[i], outputColVector);
123 * Null data entries are not set to a special non-zero value because all null math operations
124 * are checked, meaning that a zero-divide always results in a null result anyway.
129 public int getOutputColumn() {
134 public String vectorExpressionParameters() {
135 return "val " + value.toString() + ", col " + + colNum;
139 public VectorExpressionDescriptor.Descriptor getDescriptor() {
140 return (new VectorExpressionDescriptor.Builder())
142 VectorExpressionDescriptor.Mode.PROJECTION)
145 VectorExpressionDescriptor.ArgumentType.getType("decimal"),
146 VectorExpressionDescriptor.ArgumentType.getType("decimal"))
147 .setInputExpressionTypes(
148 VectorExpressionDescriptor.InputExpressionType.SCALAR,
149 VectorExpressionDescriptor.InputExpressionType.COLUMN).build();