public static Identifier quotedIdentifier(String name) { return new Identifier(name, true); }
public static Expression from(QualifiedName name) { Expression result = null; for (String part : name.getParts()) { if (result == null) { result = new Identifier(part); } else { result = new DereferenceExpression(result, new Identifier(part)); } } return result; }
private static Identifier input(String symbol) { return new Identifier(symbol); } }
private static Identifier input(String symbol) { return new Identifier(symbol); } }
public static QualifiedName of(String name) { requireNonNull(name, "name is null"); return of(ImmutableList.of(new Identifier(name))); }
private static Identifier name(String name) { return new Identifier(name); }
@Override public Node visitQuotedIdentifier(SqlBaseParser.QuotedIdentifierContext context) { String token = context.getText(); String identifier = token.substring(1, token.length() - 1) .replace("\"\"", "\""); return new Identifier(getLocation(context), identifier, true); }
@Override public Node visitQuotedIdentifier(SqlBaseParser.QuotedIdentifierContext context) { String token = context.getText(); String identifier = token.substring(1, token.length() - 1) .replace("\"\"", "\""); return new Identifier(getLocation(context), identifier, true); }
@Override public Node visitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context) { return new Identifier(getLocation(context), context.getText(), false); }
@Override public Node visitUnquotedIdentifier(SqlBaseParser.UnquotedIdentifierContext context) { return new Identifier(getLocation(context), context.getText(), false); }
@Override public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { checkState(analysis.getCoercion(node) == null, "cannot coerce a lambda expression"); ImmutableList.Builder<LambdaArgumentDeclaration> newArguments = ImmutableList.builder(); for (LambdaArgumentDeclaration argument : node.getArguments()) { Symbol symbol = lambdaDeclarationToSymbolMap.get(NodeRef.of(argument)); newArguments.add(new LambdaArgumentDeclaration(new Identifier(symbol.getName()))); } Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), null); return new LambdaExpression(newArguments.build(), rewrittenBody); }
@Override public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { checkState(analysis.getCoercion(node) == null, "cannot coerce a lambda expression"); ImmutableList.Builder<LambdaArgumentDeclaration> newArguments = ImmutableList.builder(); for (LambdaArgumentDeclaration argument : node.getArguments()) { Symbol symbol = lambdaDeclarationToSymbolMap.get(NodeRef.of(argument)); newArguments.add(new LambdaArgumentDeclaration(new Identifier(symbol.getName()))); } Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), null); return new LambdaExpression(newArguments.build(), rewrittenBody); }
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Catalog does not exist: .*") public void testSetPathInvalidCatalog() { PathSpecification invalidPathSpecification = new PathSpecification(Optional.empty(), ImmutableList.of( new PathElement(Optional.of(new Identifier("invalidCatalog")), new Identifier("thisDoesNotMatter")))); QueryStateMachine stateMachine = createQueryStateMachine("SET PATH invalidCatalog.thisDoesNotMatter"); executeSetPathTask(invalidPathSpecification, stateMachine); }
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Catalog does not exist: .*") public void testSetPathInvalidCatalog() { PathSpecification invalidPathSpecification = new PathSpecification(Optional.empty(), ImmutableList.of( new PathElement(Optional.of(new Identifier("invalidCatalog")), new Identifier("thisDoesNotMatter")))); QueryStateMachine stateMachine = createQueryStateMachine("SET PATH invalidCatalog.thisDoesNotMatter"); executeSetPathTask(invalidPathSpecification, stateMachine); }
@Test public void testDropRole() throws Exception { assertStatement("DROP ROLE role", new DropRole(new Identifier("role"))); assertStatement("DROP ROLE \"role\"", new DropRole(new Identifier("role"))); assertStatement("DROP ROLE \"ro le\"", new DropRole(new Identifier("ro le"))); assertStatement("DROP ROLE \"!@#$%^&*'ад\"\"мін\"", new DropRole(new Identifier("!@#$%^&*'ад\"мін"))); }
@Test public void testSetPath() { PathSpecification pathSpecification = new PathSpecification(Optional.empty(), ImmutableList.of( new PathElement(Optional.empty(), new Identifier("foo")))); QueryStateMachine stateMachine = createQueryStateMachine("SET PATH foo"); executeSetPathTask(pathSpecification, stateMachine); assertEquals(stateMachine.getSetPath(), "foo"); }
@Test public void testShowRoleGrants() { assertStatement("SHOW ROLE GRANTS", new ShowRoleGrants(Optional.empty(), Optional.empty())); assertStatement("SHOW ROLE GRANTS FROM catalog", new ShowRoleGrants(Optional.of(new Identifier("catalog")))); }
@Test public void testSetPath() { PathSpecification pathSpecification = new PathSpecification(Optional.empty(), ImmutableList.of( new PathElement(Optional.empty(), new Identifier("foo")))); QueryStateMachine stateMachine = createQueryStateMachine("SET PATH foo"); executeSetPathTask(pathSpecification, stateMachine); assertEquals(stateMachine.getSetPath(), "foo"); }
@Test public void testSetRole() throws Exception { assertStatement("SET ROLE ALL", new SetRole(SetRole.Type.ALL, Optional.empty())); assertStatement("SET ROLE NONE", new SetRole(SetRole.Type.NONE, Optional.empty())); assertStatement("SET ROLE role", new SetRole(SetRole.Type.ROLE, Optional.of(new Identifier("role")))); assertStatement("SET ROLE \"role\"", new SetRole(SetRole.Type.ROLE, Optional.of(new Identifier("role")))); }
@Test public void testDelete() { assertStatement("DELETE FROM t", new Delete(table(QualifiedName.of("t")), Optional.empty())); assertStatement("DELETE FROM \"awesome table\"", new Delete(table(QualifiedName.of("awesome table")), Optional.empty())); assertStatement("DELETE FROM t WHERE a = b", new Delete(table(QualifiedName.of("t")), Optional.of( new ComparisonExpression(ComparisonExpression.Operator.EQUAL, new Identifier("a"), new Identifier("b"))))); }