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

[WIP] Make PRIMARY a non-reserved keyword #22114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion presto-docs/src/main/sphinx/language/reserved.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Keyword SQL:2016 SQL-92
``ORDER`` reserved reserved
``OUTER`` reserved reserved
``PREPARE`` reserved reserved
``PRIMARY`` reserved reserved
``RECURSIVE`` reserved
``RIGHT`` reserved reserved
``ROLLUP`` reserved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,7 @@ number
;

constraintSpecification
: namedConstraintSpecification | unnamedConstraintSpecification
;

namedConstraintSpecification
: CONSTRAINT name=identifier unnamedConstraintSpecification
;

unnamedConstraintSpecification
: constraintType columnAliases constraintEnabled? constraintRely? constraintEnforced?
: (CONSTRAINT name=identifier)? constraintType columnAliases constraintEnabled? constraintRely? constraintEnforced?
;

constraintType
Expand Down Expand Up @@ -622,7 +614,7 @@ nonReserved
| MAP | MATERIALIZED | MINUTE | MONTH
| NAME | NFC | NFD | NFKC | NFKD | NO | NONE | NULLIF | NULLS
| OF | OFFSET | ONLY | OPTION | ORDINALITY | OUTPUT | OVER
| PARTITION | PARTITIONS | POSITION | PRECEDING | PRIVILEGES | PROPERTIES
| PARTITION | PARTITIONS | POSITION | PRECEDING | PRIMARY | PRIVILEGES | PROPERTIES
| RANGE | READ | REFRESH | RELY | RENAME | REPEATABLE | REPLACE | RESET | RESPECT | RESTRICT | RETURN | RETURNS | REVOKE | ROLE | ROLES | ROLLBACK | ROW | ROWS
| SCHEMA | SCHEMAS | SECOND | SECURITY | SERIALIZABLE | SESSION | SET | SETS | SQL
| SHOW | SOME | START | STATS | SUBSTRING | SYSTEM | SYSTEM_TIME | SYSTEM_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement;
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -519,34 +520,24 @@ public Node visitAddConstraint(SqlBaseParser.AddConstraintContext context)

@Override
public Node visitConstraintSpecification(SqlBaseParser.ConstraintSpecificationContext context)
{
return context.namedConstraintSpecification() != null ?
(ConstraintSpecification) visit(context.namedConstraintSpecification()) :
(ConstraintSpecification) visit(context.unnamedConstraintSpecification());
}

@Override
public Node visitNamedConstraintSpecification(SqlBaseParser.NamedConstraintSpecificationContext context)
{
ConstraintSpecification unnamedConstraint = (ConstraintSpecification) visit(context.unnamedConstraintSpecification());
return new ConstraintSpecification(getLocation(context),
Optional.of(visit(context.name).toString()),
unnamedConstraint.getColumns(),
unnamedConstraint.getConstraintType(),
unnamedConstraint.isEnabled(),
unnamedConstraint.isRely(),
unnamedConstraint.isEnforced());
}

@Override
public Node visitUnnamedConstraintSpecification(SqlBaseParser.UnnamedConstraintSpecificationContext context)
{
List<Identifier> columnAliases = visit(context.columnAliases().identifier(), Identifier.class);

boolean enabled = context.constraintEnabled() == null || context.constraintEnabled().DISABLED() == null;
boolean rely = context.constraintRely() == null || context.constraintRely().NOT() == null;
boolean enforced = context.constraintEnforced() == null || context.constraintEnforced().NOT() == null;

// Named constraint
if (context.CONSTRAINT() != null) {
return new ConstraintSpecification(getLocation(context),
Optional.of(visit(context.name).toString()),
columnAliases.stream().map(Identifier::toString).collect(toImmutableList()),
getConstraintType((Token) context.constraintType().getChild(0).getPayload()),
enabled,
rely,
enforced);
}
// Unnammed constraint
return new ConstraintSpecification(getLocation(context),
Optional.empty(),
columnAliases.stream().map(Identifier::toString).collect(toImmutableList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ public void testStatementBuilder()
printStatement("create table t1 (c1 int, c2 varchar, c3 double, c4 int, constraint pk1 primary key (c1, c2))");
printStatement("create table t1 (c1 int, c2 varchar, c3 double, c4 int, constraint pk1 primary key (c1, c2), constraint uq1 unique (c4), unique (c3))");
printStatement("create table t1 (c1 int, c2 varchar, c3 double, c4 int, constraint pk1 primary key (c1, c2) disabled not rely enforced , constraint uq1 unique (c4) not rely enforced, unique (c3) disabled)");
// primary is not a keyword and may be used as a column name
printStatement("select primary, secondary from foo a (primary, secondary)");
}

@Test
Expand Down
Loading