Skip to content

Commit af83d9d

Browse files
committed
Merge branch 'master' into HIVE-29059-show_create_table_truncates_after_tab
2 parents 061c164 + 9e38b8a commit af83d9d

13 files changed

Lines changed: 517 additions & 7 deletions

File tree

itests/src/test/resources/testconfiguration.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ minillap.query.files=\
181181
skip_header_footer_aggr.q,\
182182
skip_header_footer_proj.q,\
183183
str_to_map.q,\
184+
str_to_map_utf8.q,\
184185
table_nonprintable.q,\
185186
temp_table_add_part_with_loc.q,\
186187
temp_table_add_partition_with_location.q,\

ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,17 @@ public static boolean isRuntimeConstant(GenericUDF genericUDF) {
15301530
return false;
15311531
}
15321532

1533+
/**
1534+
* Returns whether the return type of a GenericUDF is nullable.
1535+
*/
1536+
public static boolean isNullable(GenericUDF genericUDF) {
1537+
if (genericUDF == null) {
1538+
return true;
1539+
}
1540+
UDFType udfType = AnnotationUtils.getAnnotation(genericUDF.getClass(), UDFType.class);
1541+
return udfType == null || udfType.nullable();
1542+
}
1543+
15331544
/**
15341545
* Returns whether the expression, for a single query, returns the same result given
15351546
* the same arguments/children. This includes deterministic functions as well as runtime

ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorAssignRow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.hadoop.hive.ql.exec.vector;
2020

21+
import java.nio.charset.StandardCharsets;
2122
import java.util.ArrayList;
2223
import java.util.List;
2324
import java.util.Map;
@@ -465,7 +466,7 @@ private void assignRowColumn(
465466
{
466467
if (object instanceof String) {
467468
String string = (String) object;
468-
byte[] bytes = string.getBytes();
469+
byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
469470
((BytesColumnVector) columnVector).setVal(
470471
batchIndex, bytes, 0, bytes.length);
471472
} else {

ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedBatchUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,17 @@ private static void setVector(Object row,
520520
}
521521
break;
522522
case DECIMAL:
523-
DecimalColumnVector dcv = (DecimalColumnVector) batch.cols[offset + colIndex];
523+
ColumnVector dcv = batch.cols[offset + colIndex];
524524
if (writableCol != null) {
525525
dcv.isNull[rowIndex] = false;
526526
HiveDecimalWritable wobj = (HiveDecimalWritable) writableCol;
527-
dcv.set(rowIndex, wobj);
527+
((IDecimalColumnVector) dcv).set(rowIndex, wobj);
528528
} else {
529529
setNullColIsNullValue(dcv, rowIndex);
530530
}
531531
break;
532532
default:
533-
throw new HiveException("Vectorizaton is not supported for datatype:" +
533+
throw new HiveException("Vectorization is not supported for datatype:" +
534534
poi.getPrimitiveCategory());
535535
}
536536
}

ql/src/java/org/apache/hadoop/hive/ql/parse/type/HiveFunctionHelper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,16 @@ public RelDataType getReturnType(FunctionInfo fi, List<RexNode> inputs)
135135
inputsOIs[i] = createObjectInspector(inputs.get(i));
136136
}
137137
// 2) Initialize and obtain return type
138-
ObjectInspector oi = fi.getGenericUDF() != null ?
139-
fi.getGenericUDF().initializeAndFoldConstants(inputsOIs) :
138+
GenericUDF genericUDF = fi.getGenericUDF();
139+
ObjectInspector oi = genericUDF != null ?
140+
genericUDF.initializeAndFoldConstants(inputsOIs) :
140141
fi.getGenericUDTF().initialize(inputsOIs);
141142
// 3) Convert to RelDataType
142143
return TypeConverter.convert(
143-
TypeInfoUtils.getTypeInfoFromObjectInspector(oi), rexBuilder.getTypeFactory());
144+
TypeInfoUtils.getTypeInfoFromObjectInspector(oi),
145+
FunctionRegistry.isNullable(genericUDF),
146+
rexBuilder.getTypeFactory()
147+
);
144148
}
145149

146150
/**

ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNotNull.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.hadoop.hive.ql.exec.vector.expressions.IsNotNull;
2626
import org.apache.hadoop.hive.ql.exec.vector.expressions.SelectColumnIsNotNull;
2727
import org.apache.hadoop.hive.ql.metadata.HiveException;
28+
import org.apache.hadoop.hive.ql.udf.UDFType;
2829
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
2930
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
3031
import org.apache.hadoop.io.BooleanWritable;
@@ -37,6 +38,7 @@
3738
value = "_FUNC_ a - Returns true if a is not NULL and false otherwise")
3839
@VectorizedExpressions({IsNotNull.class, SelectColumnIsNotNull.class})
3940
@NDV(maxNdv = 2)
41+
@UDFType(nullable = false)
4042
public class GenericUDFOPNotNull extends GenericUDF {
4143
private final BooleanWritable result = new BooleanWritable();
4244

ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFOPNull.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.hadoop.hive.ql.exec.vector.expressions.IsNull;
2626
import org.apache.hadoop.hive.ql.exec.vector.expressions.SelectColumnIsNull;
2727
import org.apache.hadoop.hive.ql.metadata.HiveException;
28+
import org.apache.hadoop.hive.ql.udf.UDFType;
2829
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
2930
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
3031
import org.apache.hadoop.io.BooleanWritable;
@@ -36,6 +37,7 @@
3637
@Description(name = "isnull", value = "_FUNC_ a - Returns true if a is NULL and false otherwise")
3738
@VectorizedExpressions({IsNull.class, SelectColumnIsNull.class})
3839
@NDV(maxNdv = 2)
40+
@UDFType(nullable = false)
3941
public class GenericUDFOPNull extends GenericUDF {
4042
private final BooleanWritable result = new BooleanWritable();
4143

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
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
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.hadoop.hive.ql.exec.vector;
21+
22+
import java.util.List;
23+
24+
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
25+
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
26+
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
27+
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
28+
import org.apache.hadoop.io.DataOutputBuffer;
29+
import org.junit.Assert;
30+
import org.junit.Test;
31+
32+
public class TestVectorizedBatchUtil {
33+
34+
@Test
35+
public void testSetDecimal64ColumnVector() throws Exception {
36+
Decimal64ColumnVector dec64ColVector = new Decimal64ColumnVector(10, 2);
37+
VectorizedRowBatch batch = new VectorizedRowBatch(1);
38+
batch.cols[0] = dec64ColVector;
39+
40+
Object[] row = new Object[] {new HiveDecimalWritable("123.45")};
41+
42+
StructObjectInspector oi =
43+
ObjectInspectorFactory.getStandardStructObjectInspector(
44+
List.of("col1"),
45+
List.of(PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector));
46+
47+
DataOutputBuffer buffer = new DataOutputBuffer();
48+
49+
try {
50+
VectorizedBatchUtil.addProjectedRowToBatchFrom(row, oi, 0, batch, buffer);
51+
52+
Assert.assertEquals(12345L, dec64ColVector.vector[0]);
53+
} catch (ClassCastException e) {
54+
Assert.fail(
55+
"ClassCastException thrown when adding projected row with Decimal64ColumnVector: "
56+
+ e.getMessage());
57+
}
58+
}
59+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE test (id INT, name STRING);
2+
3+
-- always FALSE
4+
EXPLAIN CBO SELECT id, (name IS NULL) IS NULL FROM test;
5+
6+
-- always FALSE
7+
EXPLAIN CBO SELECT id, (name IS NOT NULL) IS NULL FROM test;
8+
9+
-- always TRUE
10+
EXPLAIN CBO SELECT id, (name IS NULL) IS NOT NULL FROM test;
11+
12+
-- always TRUE
13+
EXPLAIN CBO SELECT id, (name IS NOT NULL) IS NOT NULL FROM test;
14+
15+
-- always-true condition: no rows filtered
16+
EXPLAIN CBO SELECT id FROM test WHERE (name IS NULL) IS NOT NULL;
17+
18+
-- always-false condition: all rows filtered
19+
EXPLAIN CBO SELECT id FROM test WHERE (name IS NULL) IS NULL;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- HIVE-28728: STR_TO_MAP() must preserve UTF-8 in vectorized execution when JVM default charset is not UTF-8.
2+
-- Tez container opts below force US-ASCII in Tez tasks
3+
-- Use driver-level mimic for testing with llap: -Dmaven.test.jvm.args="-Dfile.encoding=US-ASCII"
4+
5+
SET tez.am.launch.cmd-opts=-Dfile.encoding=US-ASCII;
6+
SET hive.tez.java.opts=-Dfile.encoding=US-ASCII;
7+
SET hive.vectorized.execution.enabled=true;
8+
SET hive.fetch.task.conversion=none;
9+
10+
DROP TABLE IF EXISTS hive28728_src;
11+
DROP TABLE IF EXISTS hive28728_result;
12+
DROP TABLE IF EXISTS hive28728_multi;
13+
DROP TABLE IF EXISTS hive28728_result_novec;
14+
15+
CREATE TABLE hive28728_src (id string, name string, multi string) STORED AS ORC;
16+
INSERT INTO hive28728_src VALUES
17+
('100','hive', 'en:1'),
18+
('200','spark', null),
19+
('300','oozie', 'a:1,b:2'),
20+
('400','airflow', 'ascii:值'),
21+
('500','优惠活动', '上海:北京,优惠活动:折扣'),
22+
('600','日本語', 'val:1,val:2');
23+
24+
SELECT STR_TO_MAP(CONCAT(id, ':', name), ',', ':') FROM hive28728_src ORDER BY id;
25+
SELECT STR_TO_MAP(multi, ',', ':') FROM hive28728_src WHERE multi IS NOT NULL ORDER BY id;
26+
SELECT STR_TO_MAP(multi, ',', ':')['优惠活动'] FROM hive28728_src WHERE id = '500';
27+
SELECT STR_TO_MAP('优惠活动:折扣,北京:海淀', ',', ':');
28+
29+
SELECT STR_TO_MAP(multi, ',', ':') FROM hive28728_src WHERE id = '200';
30+
SELECT STR_TO_MAP('700', ',', ':');
31+
32+
-- Vectorized INSERT OVERWRITE
33+
CREATE TABLE hive28728_result (cd MAP<STRING, STRING>) STORED AS ORC;
34+
INSERT OVERWRITE TABLE hive28728_result
35+
SELECT STR_TO_MAP(CONCAT(id, ':', name), ',', ':') FROM hive28728_src;
36+
SELECT * FROM hive28728_result ORDER BY cd;
37+
38+
CREATE TABLE hive28728_multi (cd MAP<STRING, STRING>) STORED AS ORC;
39+
INSERT OVERWRITE TABLE hive28728_multi
40+
SELECT STR_TO_MAP(multi, ',', ':') FROM hive28728_src WHERE multi IS NOT NULL ORDER BY id;
41+
SELECT * FROM hive28728_multi ORDER BY cd;
42+
43+
-- Non-vectorized baseline
44+
SET hive.vectorized.execution.enabled=false;
45+
CREATE TABLE hive28728_result_novec (cd MAP<STRING, STRING>) STORED AS ORC;
46+
INSERT OVERWRITE TABLE hive28728_result_novec
47+
SELECT STR_TO_MAP(CONCAT(id, ':', name), ',', ':') FROM hive28728_src;
48+
SELECT * FROM hive28728_result_novec ORDER BY cd;
49+
50+
SELECT STR_TO_MAP(CONCAT(id, ':', name), ',', ':') FROM hive28728_src ORDER BY id;
51+
52+
DROP TABLE IF EXISTS hive28728_src;
53+
DROP TABLE IF EXISTS hive28728_result;
54+
DROP TABLE IF EXISTS hive28728_multi;
55+
DROP TABLE IF EXISTS hive28728_result_novec;

0 commit comments

Comments
 (0)