Skip to content

Commit

Permalink
always allow unquote keywords as column names
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGe00 committed Sep 26, 2024
1 parent a8b86e7 commit e8cbdd0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,17 +657,7 @@ import org.slf4j.LoggerFactory;
this.hiveConf = hiveConf;
}
protected boolean useSQL11ReservedKeywordsForIdentifier() {
try {
/*
* Use the config string hive.support.sql11.reserved.keywords directly as
* HiveConf.ConfVars.HIVE_SUPPORT_SQL11_RESERVED_KEYWORDS might not be available in the hive-common present in the
* classpath during translation triggering the exception path defaulting to false
*/
return !hiveConf.get("hive.support.sql11.reserved.keywords").equalsIgnoreCase("true");
} catch (Throwable throwable) {
LOG.warn(throwable.getMessage());
return false;
}
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -105,20 +104,8 @@ public SqlNode processSql(String sql) {
return process(sql, null);
}

/**
* Returns true if the view is created using spark sql. This relies on the presence of the
* spark.sql.create.version property in the views when created using spark sql.
*
* @param hiveView
* @return true if the view is created using spark sql
*/
private static boolean isCreatedUsingSpark(Table hiveView) {
Map<String, String> tableParams = hiveView.getParameters();
return tableParams != null && tableParams.containsKey("spark.sql.create.version");
}

public SqlNode process(String sql, @Nullable Table hiveView) {
ParseDriver pd = new CoralParseDriver(hiveView != null && isCreatedUsingSpark(hiveView));
ParseDriver pd = new CoralParseDriver();
try {
ASTNode root = pd.parse(sql);
return processAST(root, hiveView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,13 @@
import org.antlr.runtime.TokenRewriteStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.conf.HiveConf;


public class CoralParseDriver extends ParseDriver {

private static final Log LOG =
LogFactory.getLog("com.linkedin.coral.hive.hive2rel.parsetree.parser.CoralParseDriver");

private boolean useSQL11ReservedKeywordsForIdentifier;

public CoralParseDriver(boolean useSQL11ReservedKeywordsForIdentifier) {
super();
this.useSQL11ReservedKeywordsForIdentifier = useSQL11ReservedKeywordsForIdentifier;
}

public CoralParseDriver() {
super();
this.useSQL11ReservedKeywordsForIdentifier = false;
}

@Override
public ASTNode parse(String command) throws ParseException {
if (LOG.isDebugEnabled()) {
Expand All @@ -42,17 +29,6 @@ public ASTNode parse(String command) throws ParseException {
HiveLexerCoral lexer = new HiveLexerCoral(new ANTLRNoCaseStringStream(command));
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
HiveParser parser = new HiveParser(tokens);
HiveConf hiveConf = new HiveConf();
/*
* This enables usage of keywords as column names without adding backquotes. This is required for translating views
* created using spark engine as certain keywords in hive like timestamp are not keywords in spark. This will
* result in creation of views without backquoting those keywords. This will be removed when coral-spark becomes
* a supported LHS for translations.
*/
if (useSQL11ReservedKeywordsForIdentifier) {
hiveConf.set("hive.support.sql11.reserved.keywords", "false");
parser.setHiveConf(hiveConf);
}
parser.setTreeAdaptor(adaptor);
HiveParser.statement_return r = null;
try {
Expand Down

0 comments on commit e8cbdd0

Please sign in to comment.