@Test public void testExecute() { assertStatement("EXECUTE myquery", new Execute(identifier("myquery"), emptyList())); }
@Override protected Void visitExecute(Execute node, Integer indent) { append(indent, "EXECUTE "); builder.append(node.getName()); List<Expression> parameters = node.getParameters(); if (!parameters.isEmpty()) { builder.append(" USING "); Joiner.on(", ").appendTo(builder, parameters); } return null; }
public String getPreparedStatementFromExecute(Execute execute) { return getPreparedStatement(execute.getName().getValue()); }
public PreparedQuery prepareQuery(Session session, Statement wrappedStatement) throws ParsingException, PrestoException, SemanticException { Statement statement = unwrapExecuteStatement(wrappedStatement, sqlParser, session); if (statement instanceof Explain && ((Explain) statement).isAnalyze()) { Statement innerStatement = ((Explain) statement).getStatement(); Optional<QueryType> innerQueryType = StatementUtils.getQueryType(innerStatement.getClass()); if (!innerQueryType.isPresent() || innerQueryType.get() == QueryType.DATA_DEFINITION) { throw new PrestoException(NOT_SUPPORTED, "EXPLAIN ANALYZE doesn't support statement type: " + innerStatement.getClass().getSimpleName()); } } List<Expression> parameters = ImmutableList.of(); if (wrappedStatement instanceof Execute) { parameters = ((Execute) wrappedStatement).getParameters(); } validateParameters(statement, parameters); return new PreparedQuery(statement, parameters); }
@Override protected Void visitExecute(Execute node, Integer indent) { append(indent, "EXECUTE "); builder.append(node.getName()); List<Expression> parameters = node.getParameters(); if (!parameters.isEmpty()) { builder.append(" USING "); Joiner.on(", ").appendTo(builder, tableNameMapper, columnNameMapper, queryWithTables, escapeIdentifier); } return null; }
@Override public Node visitExecute(SqlBaseParser.ExecuteContext context) { return new Execute( getLocation(context), (Identifier) visit(context.identifier()), visit(context.expression(), Expression.class)); }
@Override protected Void visitExecute(Execute node, Integer indent) { append(indent, "EXECUTE "); builder.append(node.getName()); List<Expression> parameters = node.getParameters(); if (!parameters.isEmpty()) { builder.append(" USING "); Joiner.on(", ").appendTo(builder, parameters); } return null; }
@Test public void testPrepareInvalidStatement() { Statement statement = new Execute(identifier("foo"), emptyList()); String sqlString = "PREPARE my_query FROM EXECUTE foo"; try { executePrepare("my_query", statement, sqlString, TEST_SESSION); fail("expected exception"); } catch (PrestoException e) { assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode()); assertEquals(e.getMessage(), "Invalid statement type for prepared statement: EXECUTE"); } }
@Test public void testExecuteWithUsing() { assertStatement("EXECUTE myquery USING 1, 'abc', ARRAY ['hello']", new Execute(identifier("myquery"), ImmutableList.of(new LongLiteral("1"), new StringLiteral("abc"), new ArrayConstructor(ImmutableList.of(new StringLiteral("hello")))))); }
@Test public void testExecute() { assertStatement("EXECUTE myquery", new Execute(identifier("myquery"), emptyList())); }
@Override public Node visitExecute(SqlBaseParser.ExecuteContext context) { return new Execute( getLocation(context), (Identifier) visit(context.identifier()), visit(context.expression(), Expression.class)); }
@Test public void testExecuteWithUsing() { assertStatement("EXECUTE myquery USING 1, 'abc', ARRAY ['hello']", new Execute(identifier("myquery"), ImmutableList.of(new LongLiteral("1"), new StringLiteral("abc"), new ArrayConstructor(ImmutableList.of(new StringLiteral("hello")))))); }