Skip to content

Commit 92b45f8

Browse files
HIVE-28197: Add deserializer to convert JSON plans to RelNodes
1 parent 97a9677 commit 92b45f8

File tree

244 files changed

+6027
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+6027
-181
lines changed

iceberg/iceberg-handler/src/test/results/positive/iceberg_explain_formatted.q.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ POSTHOOK: query: explain formatted select * from test
1414
POSTHOOK: type: QUERY
1515
POSTHOOK: Input: default@test
1616
POSTHOOK: Output: hdfs://### HDFS PATH ###
17-
{"CBOPlan":"{\n \"rels\": [\n {\n \"id\": \"0\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"test\"\n ],\n \"table:alias\": \"test\",\n \"inputs\": [],\n \"rowCount\": 1.0,\n \"avgRowSize\": 8.0,\n \"rowType\": {\n \"fields\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"a\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"b\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"PARTITION__SPEC__ID\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"PARTITION__HASH\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"FILE__PATH\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"ROW__POSITION\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"PARTITION__PROJECTION\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"SNAPSHOT__ID\"\n }\n ],\n \"nullable\": false\n },\n \"colStats\": [\n {\n \"name\": \"a\",\n \"ndv\": 1,\n \"minValue\": -2147483648,\n \"maxValue\": 2147483647\n },\n {\n \"name\": \"b\",\n \"ndv\": 1,\n \"minValue\": -2147483648,\n \"maxValue\": 2147483647\n }\n ]\n },\n {\n \"id\": \"1\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"a\",\n \"b\"\n ],\n \"exprs\": [\n {\n \"input\": 0,\n \"name\": \"$0\"\n },\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ],\n \"rowCount\": 1.0\n }\n ]\n}","optimizedSQL":"SELECT `a`, `b`\nFROM `default`.`test`","cboInfo":"Plan optimized by CBO.","STAGE DEPENDENCIES":{"Stage-0":{"ROOT STAGE":"TRUE"}},"STAGE PLANS":{"Stage-0":{"Fetch Operator":{"limit:":"-1","Processor Tree:":{"TableScan":{"alias:":"test","columns:":["a","b"],"database:":"default","table:":"test","isTempTable:":"false","OperatorId:":"TS_0","children":{"Select Operator":{"expressions:":"a (type: int), b (type: int)","columnExprMap:":{"_col0":"a","_col1":"b"},"outputColumnNames:":["_col0","_col1"],"OperatorId:":"SEL_1","children":{"ListSink":{"OperatorId:":"LIST_SINK_3"}}}}}}}}}}
17+
{"CBOPlan":"{\n \"rels\": [\n {\n \"id\": \"0\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"test\"\n ],\n \"table:alias\": \"test\",\n \"inputs\": [],\n \"rowType\": {\n \"fields\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"a\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"b\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"PARTITION__SPEC__ID\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"PARTITION__HASH\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"FILE__PATH\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"ROW__POSITION\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"PARTITION__PROJECTION\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"SNAPSHOT__ID\"\n }\n ],\n \"nullable\": false\n },\n \"virtualColumns\": [\n \"PARTITION__SPEC__ID\",\n \"PARTITION__HASH\",\n \"FILE__PATH\",\n \"ROW__POSITION\",\n \"PARTITION__PROJECTION\",\n \"SNAPSHOT__ID\"\n ],\n \"rowCount\": 1.0,\n \"avgRowSize\": 8.0,\n \"colStats\": [\n {\n \"name\": \"a\",\n \"ndv\": 1,\n \"minValue\": -2147483648,\n \"maxValue\": 2147483647\n },\n {\n \"name\": \"b\",\n \"ndv\": 1,\n \"minValue\": -2147483648,\n \"maxValue\": 2147483647\n }\n ]\n },\n {\n \"id\": \"1\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"a\",\n \"b\"\n ],\n \"exprs\": [\n {\n \"input\": 0,\n \"name\": \"$0\"\n },\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ],\n \"rowCount\": 1.0\n }\n ]\n}","optimizedSQL":"SELECT `a`, `b`\nFROM `default`.`test`","cboInfo":"Plan optimized by CBO.","STAGE DEPENDENCIES":{"Stage-0":{"ROOT STAGE":"TRUE"}},"STAGE PLANS":{"Stage-0":{"Fetch Operator":{"limit:":"-1","Processor Tree:":{"TableScan":{"alias:":"test","columns:":["a","b"],"database:":"default","table:":"test","isTempTable:":"false","OperatorId:":"TS_0","children":{"Select Operator":{"expressions:":"a (type: int), b (type: int)","columnExprMap:":{"_col0":"a","_col1":"b"},"outputColumnNames:":["_col0","_col1"],"OperatorId:":"SEL_1","children":{"ListSink":{"OperatorId:":"LIST_SINK_3"}}}}}}}}}}

ql/src/java/org/apache/hadoop/hive/ql/metadata/NotNullConstraint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
package org.apache.hadoop.hive.ql.metadata;
2020

2121
import java.io.Serializable;
22+
import java.util.Arrays;
2223
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.TreeMap;
2627

27-
import com.google.common.collect.ImmutableList;
2828
import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint;
2929

3030
/**
@@ -56,7 +56,7 @@ public NotNullConstraint(List<SQLNotNullConstraint> nns, String tableName, Strin
5656
String enable = pk.isEnable_cstr()? "ENABLE": "DISABLE";
5757
String validate = pk.isValidate_cstr()? "VALIDATE": "NOVALIDATE";
5858
String rely = pk.isRely_cstr()? "RELY": "NORELY";
59-
enableValidateRely.put(pk.getNn_name(), ImmutableList.of(enable, validate, rely));
59+
enableValidateRely.put(pk.getNn_name(), Arrays.asList(enable, validate, rely));
6060
notNullConstraints.put(pk.getNn_name(), pk.getColumn_name());
6161
}
6262
}

ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveRelDistribution.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.calcite.plan.RelTraitDef;
2929
import org.apache.calcite.rel.RelDistribution;
3030
import org.apache.calcite.rel.RelDistributionTraitDef;
31+
import org.apache.calcite.rel.RelDistributions;
3132
import org.apache.calcite.rel.RelFieldCollation;
3233
import org.apache.calcite.util.mapping.IntPair;
3334
import org.apache.calcite.util.mapping.Mappings.TargetMapping;
@@ -38,6 +39,9 @@ public class HiveRelDistribution implements RelDistribution {
3839

3940
private static final Ordering<Iterable<Integer>> ORDERING = Ordering.<Integer>natural().lexicographical();
4041

42+
public static final HiveRelDistribution ANY =
43+
new HiveRelDistribution(RelDistribution.Type.ANY, RelDistributions.ANY.getKeys());
44+
4145
public static HiveRelDistribution from(
4246
List<RelFieldCollation> fieldCollations, RelDistribution.Type distributionType) {
4347
List<Integer> newDistributionKeys = new ArrayList<>(fieldCollations.size());
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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, 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.
17+
*/
18+
package org.apache.hadoop.hive.ql.optimizer.calcite;
19+
20+
import com.google.common.collect.ImmutableMap;
21+
import org.apache.calcite.avatica.util.TimeUnitRange;
22+
import org.apache.calcite.rel.core.TableModify;
23+
import org.apache.calcite.sql.JoinConditionType;
24+
import org.apache.calcite.sql.JoinType;
25+
import org.apache.calcite.sql.SqlExplain;
26+
import org.apache.calcite.sql.SqlExplainFormat;
27+
import org.apache.calcite.sql.SqlExplainLevel;
28+
import org.apache.calcite.sql.SqlInsertKeyword;
29+
import org.apache.calcite.sql.SqlJsonConstructorNullClause;
30+
import org.apache.calcite.sql.SqlJsonQueryWrapperBehavior;
31+
import org.apache.calcite.sql.SqlJsonValueEmptyOrErrorBehavior;
32+
import org.apache.calcite.sql.SqlMatchRecognize;
33+
import org.apache.calcite.sql.SqlSelectKeyword;
34+
import org.apache.calcite.sql.fun.SqlTrimFunction;
35+
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan;
36+
37+
import static java.util.Objects.requireNonNull;
38+
39+
/**
40+
* Copy of org.apache.calcite.rel.externalize.RelEnumTypes as it has
41+
* a private constructor - so cannot extend.
42+
* <p>
43+
* This class is not needed if toEnum method's access is changed to
44+
* public
45+
*/
46+
public class HiveRelEnumTypes {
47+
private HiveRelEnumTypes(){}
48+
private static final ImmutableMap<String, Enum<?>> ENUM_BY_NAME;
49+
50+
static {
51+
// Build a mapping from enum constants (e.g. LEADING) to the enum
52+
// that contains them (e.g. SqlTrimFunction.Flag). If there two
53+
// enum constants have the same name, the builder will throw.
54+
final ImmutableMap.Builder<String, Enum<?>> enumByName =
55+
ImmutableMap.builder();
56+
register(enumByName, JoinConditionType.class);
57+
register(enumByName, JoinType.class);
58+
register(enumByName, SqlExplain.Depth.class);
59+
register(enumByName, SqlExplainFormat.class);
60+
register(enumByName, SqlExplainLevel.class);
61+
register(enumByName, SqlInsertKeyword.class);
62+
register(enumByName, SqlJsonConstructorNullClause.class);
63+
register(enumByName, SqlJsonQueryWrapperBehavior.class);
64+
register(enumByName, SqlJsonValueEmptyOrErrorBehavior.class);
65+
register(enumByName, SqlMatchRecognize.AfterOption.class);
66+
register(enumByName, SqlSelectKeyword.class);
67+
register(enumByName, SqlTrimFunction.Flag.class);
68+
register(enumByName, TimeUnitRange.class);
69+
register(enumByName, TableModify.Operation.class);
70+
register(enumByName, HiveTableScan.HiveTableScanTrait.class);
71+
ENUM_BY_NAME = enumByName.build();
72+
}
73+
74+
private static void register(ImmutableMap.Builder<String, Enum<?>> builder,
75+
Class<? extends Enum> aClass) {
76+
for (Enum enumConstant : aClass.getEnumConstants()) {
77+
builder.put(enumConstant.name(), enumConstant);
78+
}
79+
}
80+
81+
public static <E extends Enum<E>> E toEnum(String name) {
82+
return (E) requireNonNull(ENUM_BY_NAME.get(name));
83+
}
84+
}

0 commit comments

Comments
 (0)