Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cleanups #1877

Merged
merged 7 commits into from Nov 3, 2019
Merged

Remove unused support for non-standard identifier symbols

  • Loading branch information
electrum committed Oct 25, 2019
commit 40c3691746e57199286d23a192f9a473fc440491
@@ -769,11 +769,11 @@ DOUBLE_VALUE
;

IDENTIFIER
: (LETTER | '_') (LETTER | DIGIT | '_' | '@' | ':')*
: (LETTER | '_') (LETTER | DIGIT | '_')*
;

DIGIT_IDENTIFIER
: DIGIT (LETTER | DIGIT | '_' | '@' | ':')+
: DIGIT (LETTER | DIGIT | '_')+
;

QUOTED_IDENTIFIER

This file was deleted.

@@ -37,7 +37,6 @@
import javax.inject.Inject;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.function.Function;

@@ -68,7 +67,6 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int
.ignoredRule(SqlBaseParser.RULE_nonReserved)
.build();

private final EnumSet<IdentifierSymbol> allowedIdentifierSymbols;
private boolean enhancedErrorHandlerEnabled;

public SqlParser()
@@ -80,7 +78,6 @@ public SqlParser()
public SqlParser(SqlParserOptions options)
{
requireNonNull(options, "options is null");
allowedIdentifierSymbols = EnumSet.copyOf(options.getAllowedIdentifierSymbols());
enhancedErrorHandlerEnabled = options.isEnhancedErrorHandlerEnabled();
}

@@ -201,18 +198,6 @@ public void exitQuotedIdentifier(SqlBaseParser.QuotedIdentifierContext context)
}
}

@Override
public void exitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context)
{
String identifier = context.IDENTIFIER().getText();
for (IdentifierSymbol identifierSymbol : EnumSet.complementOf(allowedIdentifierSymbols)) {
char symbol = identifierSymbol.getSymbol();
if (identifier.indexOf(symbol) >= 0) {
throw new ParsingException("identifiers must not contain '" + identifierSymbol.getSymbol() + "'", null, context.IDENTIFIER().getSymbol().getLine(), context.IDENTIFIER().getSymbol().getCharPositionInLine());
}
}
}

@Override
public void exitBackQuotedIdentifier(SqlBaseParser.BackQuotedIdentifierContext context)
{
@@ -13,44 +13,17 @@
*/
package io.prestosql.sql.parser;

import com.google.common.collect.Iterables;

import java.util.EnumSet;

import static java.util.Objects.requireNonNull;

public class SqlParserOptions
{
private final EnumSet<IdentifierSymbol> allowedIdentifierSymbols = EnumSet.noneOf(IdentifierSymbol.class);
private boolean enhancedErrorHandlerEnabled = true;

public SqlParserOptions()
{
}

private SqlParserOptions(EnumSet<IdentifierSymbol> identifierSymbols, boolean enhancedErrorHandlerEnabled)
private SqlParserOptions(boolean enhancedErrorHandlerEnabled)
{
this.enhancedErrorHandlerEnabled = enhancedErrorHandlerEnabled;
this.allowedIdentifierSymbols.addAll(identifierSymbols);
}

public SqlParserOptions allowIdentifierSymbol(Iterable<IdentifierSymbol> identifierSymbols)
{
Iterables.addAll(allowedIdentifierSymbols, identifierSymbols);
return this;
}

public EnumSet<IdentifierSymbol> getAllowedIdentifierSymbols()
{
return EnumSet.copyOf(allowedIdentifierSymbols);
}

public SqlParserOptions allowIdentifierSymbol(IdentifierSymbol... identifierSymbols)
{
for (IdentifierSymbol identifierSymbol : identifierSymbols) {
allowedIdentifierSymbols.add(requireNonNull(identifierSymbol, "identifierSymbol is null"));
}
return this;
}

public SqlParserOptions useEnhancedErrorHandler(boolean enable)
@@ -66,6 +39,6 @@ public boolean isEnhancedErrorHandlerEnabled()

public static SqlParserOptions copyOf(SqlParserOptions other)
{
return new SqlParserOptions(other.allowedIdentifierSymbols, other.enhancedErrorHandlerEnabled);
return new SqlParserOptions(other.enhancedErrorHandlerEnabled);
}
}
@@ -167,8 +167,6 @@
import static io.prestosql.sql.QueryUtil.table;
import static io.prestosql.sql.QueryUtil.values;
import static io.prestosql.sql.SqlFormatter.formatSql;
import static io.prestosql.sql.parser.IdentifierSymbol.AT_SIGN;
import static io.prestosql.sql.parser.IdentifierSymbol.COLON;
import static io.prestosql.sql.parser.ParserAssert.expression;
import static io.prestosql.sql.parser.ParserAssert.statement;
import static io.prestosql.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DECIMAL;
@@ -681,21 +679,6 @@ public void testPrecedenceAndAssociativity()
new LongLiteral("3"))));
}

@Test
public void testAllowIdentifierColon()
{
SqlParser sqlParser = new SqlParser(new SqlParserOptions().allowIdentifierSymbol(COLON));
sqlParser.createStatement("select * from foo:bar");
}

@SuppressWarnings("deprecation")
@Test
public void testAllowIdentifierAtSign()
{
SqlParser sqlParser = new SqlParser(new SqlParserOptions().allowIdentifierSymbol(AT_SIGN));
sqlParser.createStatement("select * from foo@bar");
}

@Test
public void testInterval()
{
@@ -65,10 +65,6 @@
"line 1:19: backquoted identifiers are not supported; use double quotes to quote identifiers"},
{"select 1x from dual",
"line 1:8: identifiers must not start with a digit; surround the identifier with double quotes"},
{"select * from foo@bar",
"line 1:15: identifiers must not contain '@'"},
{"select * from foo:bar",
"line 1:15: identifiers must not contain ':'"},
{"select fuu from dual order by fuu order by fuu",
"line 1:35: mismatched input 'order'. Expecting: '%', '*', '+', ',', '-', '.', '/', 'AND', 'ASC', 'AT', 'DESC', 'FETCH', 'LIMIT', 'NULLS', 'OFFSET', 'OR', '[', '||', <EOF>, <predicate>"},
{"select fuu from dual limit 10 order by fuu",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.