kasakrisz commented on code in PR #6665:
URL: https://github.com/apache/hive/pull/6665#discussion_r3813324603
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java:
##########
@@ -4737,6 +4737,35 @@ static boolean isRegex(String pattern, HiveConf conf) {
return false;
}
+ public static String processAllColRefAndExclude(
+ ASTNode expr, RowResolver inputRR, Set<ColumnInfo> excludedColumns)
throws SemanticException {
Review Comment:
1. This can be a protected non-static method because `CalcitePlanner`
extends `SemanticAnalyzer`.
2. How about creating a custom return object that wraps `starTabAlias` and
the set of excluded columns? Currently, "output parameters" and the return
value are mixed.
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java:
##########
@@ -4737,6 +4737,35 @@ static boolean isRegex(String pattern, HiveConf conf) {
return false;
}
+ public static String processAllColRefAndExclude(
+ ASTNode expr, RowResolver inputRR, Set<ColumnInfo> excludedColumns)
throws SemanticException {
+ // Check if the query uses SELECT * EXCLUDE. If it does, grab the table
+ // alias (like t.*) and build a list of the columns the user wants to
exclude.
+ String starTabAlias = null;
+ ASTNode excludeNode = null;
+ if (expr.getChildCount() > 0) {
+ ASTNode firstChild = (ASTNode) expr.getChild(0);
+ if (firstChild.getType() == HiveParser.TOK_TABCOLNAME) {
+ excludeNode = firstChild;
+ } else {
+ starTabAlias = getUnescapedName(firstChild).toLowerCase();
+ if (expr.getChildCount() > 1) {
+ excludeNode = (ASTNode) expr.getChild(1);
+ }
+ }
+ }
+
+ if (excludeNode != null) {
Review Comment:
Currently `TOK_ALLCOLREF` has two optional children. I think a for loop with
dispatcher logic in its body would be a cleaner design. It would also better
suit adding more types of children in the future.
```
for (ASTNode child : allColRefNode) {
if (child.getType() == HiveParser.TOK_TABNAME) {
...
} else if (child.getType() == HiveParser.TOK_TABCOLNAME) {
...
} else {
throw new SemanticException
}
}
```
##########
ql/src/test/queries/clientpositive/select_exclude.q:
##########
@@ -0,0 +1,37 @@
+CREATE TABLE test_exclude (
Review Comment:
Please add
```
set hive.cli.print.header=true;
```
to the beginning of the file. IMHO, it would be beneficial to see which
column names appear in the result sets.
##########
ql/src/test/queries/clientpositive/select_exclude.q:
##########
@@ -0,0 +1,37 @@
+CREATE TABLE test_exclude (
+ id INT,
+ name STRING,
+ email STRING,
+ address STRING,
+ phone STRING
+);
+
+INSERT INTO test_exclude VALUES (1, 'Alice', '[email protected]', '123 Apple St',
'555-0100');
+INSERT INTO test_exclude VALUES (2, 'Bob', '[email protected]', '456 Banana Ave',
'555-0200');
+
+-- Exclude a single column
+EXPLAIN SELECT * EXCLUDE (email) FROM test_exclude;
+SELECT * EXCLUDE (email) FROM test_exclude;
+
+-- Exclude multiple columns
+EXPLAIN SELECT * EXCLUDE (email, address, phone) FROM test_exclude;
+SELECT * EXCLUDE (email, address, phone) FROM test_exclude;
+
+-- Exclude with table alias
+EXPLAIN SELECT t.* EXCLUDE (id, phone) FROM test_exclude t;
+SELECT t.* EXCLUDE (id, phone) FROM test_exclude t;
+
+-- Exclude with JOIN
+CREATE TABLE test_exclude_join (
+ id INT,
+ department STRING
+);
+INSERT INTO test_exclude_join VALUES (1, 'Engineering');
+INSERT INTO test_exclude_join VALUES (2, 'Sales');
Review Comment:
Could you please merge these to one insert.
##########
ql/src/test/queries/clientpositive/select_exclude.q:
##########
@@ -0,0 +1,37 @@
+CREATE TABLE test_exclude (
+ id INT,
+ name STRING,
+ email STRING,
+ address STRING,
+ phone STRING
+);
+
+INSERT INTO test_exclude VALUES (1, 'Alice', '[email protected]', '123 Apple St',
'555-0100');
+INSERT INTO test_exclude VALUES (2, 'Bob', '[email protected]', '456 Banana Ave',
'555-0200');
Review Comment:
Could you please merge these to one insert.
--
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]