zratkai commented on code in PR #5541: URL: https://github.com/apache/hive/pull/5541#discussion_r1908890703
########## iceberg/iceberg-handler/src/test/queries/positive/iceberg_create_locally_ordered_table.q: ########## @@ -0,0 +1,44 @@ +-- Mask neededVirtualColumns due to non-strict order +--! qt:replace:/(\s+neededVirtualColumns:\s)(.*)/$1#Masked#/ +-- Mask the totalSize value as it can have slight variability, causing test flakiness +--! qt:replace:/(\s+totalSize\s+)\S+(\s+)/$1#Masked#$2/ +-- Mask random uuid +--! qt:replace:/(\s+uuid\s+)\S+(\s*)/$1#Masked#$2/ +-- Mask a random snapshot id +--! qt:replace:/(\s+current-snapshot-id\s+)\S+(\s*)/$1#Masked#/ +-- Mask added file size +--! qt:replace:/(\S\"added-files-size\\\":\\\")(\d+)(\\\")/$1#Masked#$3/ +-- Mask total file size +--! qt:replace:/(\S\"total-files-size\\\":\\\")(\d+)(\\\")/$1#Masked#$3/ +-- Mask removed file size +--! qt:replace:/(\S\"removed-files-size\\\":\\\")(\d+)(\\\")/$1#Masked#$3/ +-- Mask current-snapshot-timestamp-ms +--! qt:replace:/(\s+current-snapshot-timestamp-ms\s+)\S+(\s*)/$1#Masked#$2/ +--! qt:replace:/(MAJOR\s+succeeded\s+)[a-zA-Z0-9\-\.\s+]+(\s+manual)/$1#Masked#$2/ +-- Mask iceberg version +--! qt:replace:/(\S\"iceberg-version\\\":\\\")(\w+\s\w+\s\d+\.\d+\.\d+\s\(\w+\s\w+\))(\\\")/$1#Masked#$3/ +set hive.llap.io.enabled=true; +set hive.vectorized.execution.enabled=true; +set hive.optimize.shared.work.merge.ts.schema=true; + +create table ice_orc (id int, text string) stored by iceberg stored as orc; + +insert into ice_orc values (3, "3"),(2, "2"),(4, "4"),(5, "5"),(1, "1"),(2, "3"),(3,null),(2,null),(null,"a"); + +describe formatted ice_orc; +describe extended ice_orc; +set hive.fetch.task.conversion=more; +select * from ice_orc; + +create table ice_orc_sorted (id int, text string) write locally ordered by id desc nulls first, text asc nulls last stored by iceberg stored as orc; Review Comment: Parenthesis is not supported here. ########## ql/src/java/org/apache/hadoop/hive/ql/ddl/misc/sortoder/SortFieldDesc.java: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.ddl.misc.sortoder; + +public class SortFieldDesc { Review Comment: I could not find any which I could use. ########## iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java: ########## @@ -137,6 +146,7 @@ public class HiveIcebergMetaHook implements HiveMetaHook { private static final Logger LOG = LoggerFactory.getLogger(HiveIcebergMetaHook.class); + private final ObjectMapper jsonObjectMapper = new ObjectMapper(); Review Comment: Fixed. ########## ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java: ########## @@ -14255,7 +14261,9 @@ ASTNode analyzeCreateTable( isExt = isExternalTableChanged(tblProps, isTransactional, isExt, isDefaultTableTypeChanged); addDbAndTabToOutputs(new String[] {qualifiedTabName.getDb(), qualifiedTabName.getTable()}, TableType.MANAGED_TABLE, isTemporary, tblProps, storageFormat); - + if(!Strings.isNullOrEmpty(sortOrder)) { Review Comment: Fixed. ########## ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java: ########## @@ -16089,7 +16097,26 @@ protected void addPartitionColsToInsert(List<FieldSchema> partCols, rewrittenQueryStr.append(")"); } } - + + private String getSortOrderJson(ASTNode ast) { + List<SortFieldDesc> sortFieldDescList = new ArrayList<>(); + SortFields sortFields = new SortFields(sortFieldDescList); + for (int i = 0; i < ast.getChildCount(); i++) { + ASTNode child = (ASTNode) ast.getChild(i); + SortFieldDesc.SortDirection sortDirection = child.getToken() + .getType() == HiveParser.TOK_TABSORTCOLNAMEDESC ? SortFieldDesc.SortDirection.DESC : SortFieldDesc.SortDirection.ASC; + child = (ASTNode) child.getChild(0); + String name = unescapeIdentifier(child.getChild(0).getText()).toLowerCase(); + SortFieldDesc.NullOrder nullOrder = child.getToken().getType() == HiveParser.TOK_NULLS_FIRST ? SortFieldDesc.NullOrder.NULLS_FIRST : SortFieldDesc.NullOrder.NULLS_LAST; + sortFieldDescList.add(new SortFieldDesc(name, sortDirection, nullOrder)); + } + try { + return jsonObjectMapper.writeValueAsString(sortFields); Review Comment: SerializationUtilities.serializeExpression uses base64 encoding, so it won't be human readable. ########## parser/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g: ########## @@ -2201,6 +2212,8 @@ columnNameOrder ^(TOK_TABSORTCOLNAMEDESC ^(TOK_NULLS_LAST identifier)) -> {$orderSpec.tree.getType()==HiveParser.KW_ASC}? ^(TOK_TABSORTCOLNAMEASC ^($nullSpec identifier)) + -> {$orderSpec.tree.getType()==HiveParser.KW_DESC}? Review Comment: Yes. ########## ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java: ########## @@ -14255,7 +14261,9 @@ ASTNode analyzeCreateTable( isExt = isExternalTableChanged(tblProps, isTransactional, isExt, isDefaultTableTypeChanged); addDbAndTabToOutputs(new String[] {qualifiedTabName.getDb(), qualifiedTabName.getTable()}, TableType.MANAGED_TABLE, isTemporary, tblProps, storageFormat); - + if(!Strings.isNullOrEmpty(sortOrder)) { + tblProps.put("default-sort-order", sortOrder); Review Comment: In org.apache.iceberg.TableProperties.DEFAULT_SORT_ORDER, but iceberg is not referenced in hive-exec, and adding only for this seemed unnecessary. -- 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]
