deniskuzZ commented on code in PR #6413:
URL: https://github.com/apache/hive/pull/6413#discussion_r3380583198
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsAutoGatherContext.java:
##########
@@ -274,50 +276,71 @@ private void replaceSelectOperatorProcess(SelectOperator
operator, Operator<? ex
columnExprMap.put(internalName, exprNodeDesc);
signature.add(selRSSig.get(selRSIdx));
}
+ int dynPartsCount=0;
+ if (partSpec != null) {
+ for (Map.Entry<String, String> entry : partSpec.entrySet()) {
+ if (entry.getValue() == null) {
+ dynPartsCount++;
+ }
+ }
+ }
+ boolean inputRRHasStaticParts = (this.columns.size() + dynPartsCount <
columns.size());
// if there is any partition column (in static partition or dynamic
// partition or mixed case)
- int dynamicPartBegin = -1;
+ int dynamicPartBegin = 0;
Review Comment:
can we refactor
````
for (FieldSchema column : this.columns) {
int index = tbl.getColumnIndexByName(column.getName());
ColumnInfo col = columns.get(index);
Integer selRSIdx = getSelRSColumnIndex(column.getName(), col,
columnNameToIndex);
if (selRSIdx == null) {
continue;
}
ExprNodeDesc exprNodeDesc = new ExprNodeColumnDesc(col);
colList.add(exprNodeDesc);
String internalName = selRS.getColumnNames().get(selRSIdx);
columnNames.add(internalName);
columnExprMap.put(internalName, exprNodeDesc);
signature.add(selRSSig.get(selRSIdx));
}
int dynPartsCount = 0;
if (partSpec != null) {
for (Map.Entry<String, String> entry : partSpec.entrySet()) {
if (entry.getValue() == null) {
dynPartsCount++;
}
}
}
// True when the input row already carries the static partition columns
as real columns (e.g. Iceberg),
// i.e. it has more columns than just the data columns plus the dynamic
partition columns.
boolean inputRRHasStaticParts = (this.columns.size() + dynPartsCount <
columns.size());
// Column layout produced for the stats-gathering select:
// <-- non-partition cols -->|<-- static partition cols -->|<--
dynamic partition cols -->
// For non-native tables (e.g. Iceberg) partition columns are ordinary
interleaved columns instead.
boolean hasDynamicPart = false;
// Count of native static partition columns already emitted as
constants. They are absent from the input
// row, so each one shifts the input position of the columns that follow
it.
int staticPartShift = 0;
for (int i = 0; i < partitionColumns.size(); i++) {
String partColName = partitionColumns.get(i).getName();
int tableIndex = tbl.getColumnIndexByName(partColName);
boolean isStaticPartition = partSpec != null &&
partSpec.containsKey(partColName)
&& partSpec.get(partColName) != null;
ExprNodeDesc exprNodeDesc;
// 2. deal with static partition columns
if (isStaticPartition) {
if (hasDynamicPart) {
throw new SemanticException(
"Dynamic partition columns should not come before static
partition columns.");
}
if (inputRRHasStaticParts) {
// non-native (e.g. Iceberg): the partition column is a real
column in the input row
exprNodeDesc = new ExprNodeColumnDesc(columns.get(tableIndex -
staticPartShift));
} else {
// native: the static partition value is a constant, not present
in the input row
exprNodeDesc = new ExprNodeConstantDesc(partSpec.get(partColName));
staticPartShift++;
}
}
// 3. dynamic partition columns: always read from the input row
else {
hasDynamicPart = true;
exprNodeDesc = new ExprNodeColumnDesc(columns.get(tableIndex -
staticPartShift));
}
TypeInfo srcType = exprNodeDesc.getTypeInfo();
// For non-native tables partition columns are interleaved, so find
the select-RS position by name;
// for native tables it equals the table column index.
int selRSIndex = inputRRHasStaticParts ?
columnNameToIndex.get(partColName) : tableIndex;
TypeInfo destType = selRSSig.get(selRSIndex).getType();
if (!srcType.equals(destType)) {
// This may be possible when srcType is string but destType is
integer
exprNodeDesc = ExprNodeTypeCheck.getExprNodeDefaultExprProcessor()
.createConversionCast(exprNodeDesc, (PrimitiveTypeInfo)
destType);
}
colList.add(exprNodeDesc);
String internalName = selRS.getColumnNames().get(selRSIndex);
columnNames.add(internalName);
columnExprMap.put(internalName, exprNodeDesc);
signature.add(selRSSig.get(selRSIndex));
}
````
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]