jcamachor commented on a change in pull request #1034:
URL: https://github.com/apache/hive/pull/1034#discussion_r431189978
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/parse/ColumnStatsSemanticAnalyzer.java
##########
@@ -304,15 +287,199 @@ public static String genRewrittenQuery(Table tbl,
List<String> colNames, HiveCon
}
String rewrittenQuery = rewrittenQueryBuilder.toString();
- rewrittenQuery = new VariableSubstitution(new HiveVariableSource() {
- @Override
- public Map<String, String> getHiveVariable() {
- return SessionState.get().getHiveVariables();
- }
- }).substitute(conf, rewrittenQuery);
+ rewrittenQuery = new VariableSubstitution(
+ () -> SessionState.get().getHiveVariables()).substitute(conf,
rewrittenQuery);
return rewrittenQuery;
}
+ private static void genComputeStats(StringBuilder rewrittenQueryBuilder,
HiveConf conf,
+ int pos, String columnName, TypeInfo typeInfo) throws SemanticException {
+ Preconditions.checkArgument(typeInfo.getCategory() == Category.PRIMITIVE);
+ ColumnStatsType columnStatsType =
+ ColumnStatsType.getColumnStatsType((PrimitiveTypeInfo) typeInfo);
+ // The first column is always the type
+ // The rest of columns will depend on the type itself
+ int size = columnStatsType.getColumnStats().size() - 1;
+ for (int i = 0; i < size; i++) {
+ ColumnStatsField columnStatsField =
columnStatsType.getColumnStats().get(i);
+ appendStatsField(rewrittenQueryBuilder, conf, columnStatsField,
columnStatsType,
+ columnName, pos);
+ rewrittenQueryBuilder.append(", ");
+ }
+ ColumnStatsField columnStatsField =
columnStatsType.getColumnStats().get(size);
+ appendStatsField(rewrittenQueryBuilder, conf, columnStatsField,
columnStatsType,
+ columnName, pos);
+ }
+
+ private static void appendStatsField(StringBuilder rewrittenQueryBuilder,
HiveConf conf,
+ ColumnStatsField columnStatsField, ColumnStatsType columnStatsType,
+ String columnName, int pos) throws SemanticException {
+ switch (columnStatsField) {
+ case COLUMN_TYPE:
+ appendColumnType(rewrittenQueryBuilder, conf, columnStatsType, pos);
Review comment:
This is kind of misleading because `column_type` does not always match
the actual column type, e.g., BYTE, SHORT, INT or BIGINT are all mapped to the
same column stats type (LONG). However, I did not want to change the internal
name that was used before in this patch too. I renamed the enum to
`COLUMN_STATS_TYPE` to add some more clarity.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]