Search in sources :

Example 11 with QualifiedName

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));
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) SetSession(com.facebook.presto.sql.tree.SetSession) QualifiedName(com.facebook.presto.sql.tree.QualifiedName)

Example 12 with QualifiedName

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)));
    }
}
Also used : CreateTable(com.facebook.presto.sql.tree.CreateTable) DropTable(com.facebook.presto.sql.tree.DropTable) Table(com.facebook.presto.sql.tree.Table) RenameTable(com.facebook.presto.sql.tree.RenameTable) ShowStats(com.facebook.presto.sql.tree.ShowStats) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) Test(org.testng.annotations.Test)

Example 13 with 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()));
}
Also used : CreateTable(com.facebook.presto.sql.tree.CreateTable) DropTable(com.facebook.presto.sql.tree.DropTable) Table(com.facebook.presto.sql.tree.Table) RenameTable(com.facebook.presto.sql.tree.RenameTable) Identifier(com.facebook.presto.sql.tree.Identifier) QueryUtil.quotedIdentifier(com.facebook.presto.sql.QueryUtil.quotedIdentifier) Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) WithQuery(com.facebook.presto.sql.tree.WithQuery) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) WithQuery(com.facebook.presto.sql.tree.WithQuery) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) Values(com.facebook.presto.sql.tree.Values) With(com.facebook.presto.sql.tree.With) Test(org.testng.annotations.Test)

Example 14 with QualifiedName

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));
}
Also used : Query(com.facebook.presto.sql.tree.Query) QueryUtil.simpleQuery(com.facebook.presto.sql.QueryUtil.simpleQuery) WithQuery(com.facebook.presto.sql.tree.WithQuery) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) AllColumns(com.facebook.presto.sql.tree.AllColumns) Insert(com.facebook.presto.sql.tree.Insert) Test(org.testng.annotations.Test)

Example 15 with QualifiedName

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");
}
Also used : AlterRoutineCharacteristics(com.facebook.presto.sql.tree.AlterRoutineCharacteristics) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) AlterFunction(com.facebook.presto.sql.tree.AlterFunction) Test(org.testng.annotations.Test)

Aggregations

QualifiedName (com.facebook.presto.sql.tree.QualifiedName)17 Identifier (com.facebook.presto.sql.tree.Identifier)7 Test (org.testng.annotations.Test)7 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)5 QueryUtil.quotedIdentifier (com.facebook.presto.sql.QueryUtil.quotedIdentifier)4 AllColumns (com.facebook.presto.sql.tree.AllColumns)4 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)4 CreateTableAsSelect (com.facebook.presto.sql.tree.CreateTableAsSelect)4 Query (com.facebook.presto.sql.tree.Query)4 CreateTable (com.facebook.presto.sql.tree.CreateTable)3 DropTable (com.facebook.presto.sql.tree.DropTable)3 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)3 Table (com.facebook.presto.sql.tree.Table)3 ArrayList (java.util.ArrayList)3 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)2 ArrayConstructor (com.facebook.presto.sql.tree.ArrayConstructor)2 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)2 Expression (com.facebook.presto.sql.tree.Expression)2 InPredicate (com.facebook.presto.sql.tree.InPredicate)2 Insert (com.facebook.presto.sql.tree.Insert)2