use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.
the class TestSetSessionTask method testSetSessionWithParameters.
private void testSetSessionWithParameters(String property, Expression expression, String expectedValue, List<Expression> parameters) {
QualifiedName qualifiedPropName = QualifiedName.of(CATALOG_NAME, property);
String sqlString = format("set %s = 'old_value'", qualifiedPropName);
QueryStateMachine stateMachine = createQueryStateMachine(sqlString, TEST_SESSION, false, transactionManager, executor, metadata);
SetSessionTask sessionTask = new SetSessionTask();
getFutureValue(sessionTask.execute(new SetSession(qualifiedPropName, expression), transactionManager, metadata, accessControl, stateMachine, parameters));
Map<String, String> sessionProperties = stateMachine.getSetSessionProperties();
assertEquals(sessionProperties, ImmutableMap.of(qualifiedPropName.toString(), expectedValue));
}
use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.
the class TestSqlParser method testShowStats.
@Test
public void testShowStats() {
final String[] tableNames = { "t", "s.t", "c.s.t" };
for (String fullName : tableNames) {
QualifiedName qualifiedName = makeQualifiedName(fullName);
assertStatement(format("SHOW STATS FOR %s", qualifiedName), new ShowStats(new Table(qualifiedName)));
}
}
use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.
the class TestSqlParser method testCreateTableAsWith.
@Test
public void testCreateTableAsWith() {
String queryParenthesizedWith = "CREATE TABLE foo " + "AS " + "( WITH t(x) AS (VALUES 1) " + "TABLE t ) " + "WITH NO DATA";
String queryUnparenthesizedWith = "CREATE TABLE foo " + "AS " + "WITH t(x) AS (VALUES 1) " + "TABLE t " + "WITH NO DATA";
String queryParenthesizedWithHasAlias = "CREATE TABLE foo(a) " + "AS " + "( WITH t(x) AS (VALUES 1) " + "TABLE t ) " + "WITH NO DATA";
String queryUnparenthesizedWithHasAlias = "CREATE TABLE foo(a) " + "AS " + "WITH t(x) AS (VALUES 1) " + "TABLE t " + "WITH NO DATA";
QualifiedName table = QualifiedName.of("foo");
Query query = new Query(Optional.of(new With(false, ImmutableList.of(new WithQuery(identifier("t"), query(new Values(ImmutableList.of(new LongLiteral("1")))), Optional.of(ImmutableList.of(identifier("x"))))))), new Table(QualifiedName.of("t")), Optional.empty(), Optional.empty(), Optional.empty());
assertStatement(queryParenthesizedWith, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
assertStatement(queryUnparenthesizedWith, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
assertStatement(queryParenthesizedWithHasAlias, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("a"))), Optional.empty()));
assertStatement(queryUnparenthesizedWithHasAlias, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("a"))), Optional.empty()));
}
use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.
the class TestSqlParser method testInsertInto.
@Test
public void testInsertInto() {
QualifiedName table = QualifiedName.of("a");
Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
assertStatement("INSERT INTO a SELECT * FROM t", new Insert(table, Optional.empty(), query));
assertStatement("INSERT INTO a (c1, c2) SELECT * FROM t", new Insert(table, Optional.of(ImmutableList.of(identifier("c1"), identifier("c2"))), query));
}
use of com.facebook.presto.sql.tree.QualifiedName in project presto by prestodb.
the class TestSqlParser method testAlterFunction.
@Test
public void testAlterFunction() {
QualifiedName functionName = QualifiedName.of("testing", "default", "tan");
assertStatement("ALTER FUNCTION testing.default.tan\n" + "CALLED ON NULL INPUT", new AlterFunction(functionName, Optional.empty(), new AlterRoutineCharacteristics(Optional.of(CALLED_ON_NULL_INPUT))));
assertStatement("ALTER FUNCTION testing.default.tan(double)\n" + "RETURNS NULL ON NULL INPUT", new AlterFunction(functionName, Optional.of(ImmutableList.of("double")), new AlterRoutineCharacteristics(Optional.of(RETURNS_NULL_ON_NULL_INPUT))));
assertInvalidStatement("ALTER FUNCTION testing.default.tan", "No alter routine characteristics specified");
assertInvalidStatement("ALTER FUNCTION testing.default.tan\n" + "RETURNS NULL ON NULL INPUT\n" + "RETURNS NULL ON NULL INPUT", "Duplicate null-call clause: RETURNSNULLONNULLINPUT");
}
Aggregations