Search in sources :

Example 26 with StringLiteral

use of io.trino.sql.tree.StringLiteral in project trino by trinodb.

the class TestSqlParser method testPosition.

@Test
public void testPosition() {
    assertThat(expression("position('a' in 'b')")).isEqualTo(new FunctionCall(location(1, 1), QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral(location(1, 17), "b"), new StringLiteral(location(1, 10), "a"))));
    assertThat(expression("position('a' in ('b'))")).isEqualTo(new FunctionCall(location(1, 1), QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral(location(1, 18), "b"), new StringLiteral(location(1, 10), "a"))));
}
Also used : StringLiteral(io.trino.sql.tree.StringLiteral) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.junit.jupiter.api.Test)

Example 27 with StringLiteral

use of io.trino.sql.tree.StringLiteral in project trino by trinodb.

the class TestSqlParser method testTableExecute.

@Test
public void testTableExecute() {
    Table table = new Table(QualifiedName.of("foo"));
    Identifier procedure = new Identifier("bar");
    assertStatement("ALTER TABLE foo EXECUTE bar", new TableExecute(table, procedure, ImmutableList.of(), Optional.empty()));
    assertStatement("ALTER TABLE foo EXECUTE bar(bah => 1, wuh => 'clap') WHERE age > 17", new TableExecute(table, procedure, ImmutableList.of(new CallArgument(identifier("bah"), new LongLiteral("1")), new CallArgument(identifier("wuh"), new StringLiteral("clap"))), Optional.of(new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, new Identifier("age"), new LongLiteral("17")))));
    assertStatement("ALTER TABLE foo EXECUTE bar(1, 'clap') WHERE age > 17", new TableExecute(table, procedure, ImmutableList.of(new CallArgument(new LongLiteral("1")), new CallArgument(new StringLiteral("clap"))), Optional.of(new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, new Identifier("age"), new LongLiteral("17")))));
}
Also used : TableExecute(io.trino.sql.tree.TableExecute) CallArgument(io.trino.sql.tree.CallArgument) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) Test(org.junit.jupiter.api.Test)

Example 28 with StringLiteral

use of io.trino.sql.tree.StringLiteral in project trino by trinodb.

the class TestSqlParser method testCreateTableAsSelect.

@Test
public void testCreateTableAsSelect() {
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
    Query querySelectColumn = simpleQuery(selectList(new Identifier("a")), table(QualifiedName.of("t")));
    Query querySelectColumns = simpleQuery(selectList(new Identifier("a"), new Identifier("b")), table(QualifiedName.of("t")));
    QualifiedName table = QualifiedName.of("foo");
    assertStatement("CREATE TABLE foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, false, ImmutableList.of(), true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) AS SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, false, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) AS SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, false, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo AS SELECT * FROM t", new CreateTableAsSelect(table, query, true, ImmutableList.of(), true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo(x) AS SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, true, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS foo(x,y) AS SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, true, ImmutableList.of(), true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo AS SELECT * FROM t WITH NO DATA", new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) AS SELECT a FROM t WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) AS SELECT a,b FROM t WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    List<Property> properties = ImmutableList.of(new Property(new Identifier("string"), new StringLiteral("bar")), new Property(new Identifier("long"), new LongLiteral("42")), new Property(new Identifier("computed"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))), new Property(new Identifier("a"), new ArrayConstructor(ImmutableList.of(new StringLiteral("v1"), new StringLiteral("v2")))));
    assertStatement("CREATE TABLE foo " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t", new CreateTableAsSelect(table, query, false, properties, true, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t", new CreateTableAsSelect(table, querySelectColumn, false, properties, true, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t", new CreateTableAsSelect(table, querySelectColumns, false, properties, true, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, query, false, properties, false, Optional.empty(), Optional.empty()));
    assertStatement("CREATE TABLE foo(x) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.empty()));
    assertStatement("CREATE TABLE foo(x,y) " + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.empty()));
    assertStatement("CREATE TABLE foo COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT * FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, query, false, properties, false, Optional.empty(), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x) COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumn, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"))), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x,y) COMMENT 'test'" + "WITH ( string = 'bar', long = 42, computed = 'ban' || 'ana', a  = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.of("test")));
    assertStatement("CREATE TABLE foo(x,y) COMMENT 'test'" + "WITH ( \"string\" = 'bar', \"long\" = 42, computed = 'ban' || 'ana', a = ARRAY[ 'v1', 'v2' ] ) " + "AS " + "SELECT a,b FROM t " + "WITH NO DATA", new CreateTableAsSelect(table, querySelectColumns, false, properties, false, Optional.of(ImmutableList.of(new Identifier("x"), new Identifier("y"))), Optional.of("test")));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) Query(io.trino.sql.tree.Query) WithQuery(io.trino.sql.tree.WithQuery) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) QualifiedName(io.trino.sql.tree.QualifiedName) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) ArrayConstructor(io.trino.sql.tree.ArrayConstructor) AllColumns(io.trino.sql.tree.AllColumns) FunctionCall(io.trino.sql.tree.FunctionCall) Property(io.trino.sql.tree.Property) Test(org.junit.jupiter.api.Test)

Example 29 with StringLiteral

use of io.trino.sql.tree.StringLiteral in project trino by trinodb.

the class TestPostgreSqlClient method testConvertLike.

@Test
public void testConvertLike() {
    // c_varchar LIKE '%pattern%'
    assertThat(JDBC_CLIENT.convertPredicate(SESSION, translateToConnectorExpression(new LikePredicate(new SymbolReference("c_varchar_symbol"), new StringLiteral("%pattern%"), Optional.empty()), Map.of("c_varchar_symbol", VARCHAR_COLUMN.getColumnType())), Map.of("c_varchar_symbol", VARCHAR_COLUMN))).hasValue("(\"c_varchar\") LIKE ('%pattern%')");
    // c_varchar LIKE '%pattern\%' ESCAPE '\'
    assertThat(JDBC_CLIENT.convertPredicate(SESSION, translateToConnectorExpression(new LikePredicate(new SymbolReference("c_varchar"), new StringLiteral("%pattern\\%"), new StringLiteral("\\")), Map.of("c_varchar", VARCHAR_COLUMN.getColumnType())), Map.of(VARCHAR_COLUMN.getColumnName(), VARCHAR_COLUMN))).hasValue("(\"c_varchar\") LIKE ('%pattern\\%') ESCAPE ('\\')");
}
Also used : StringLiteral(io.trino.sql.tree.StringLiteral) SymbolReference(io.trino.sql.tree.SymbolReference) LikePredicate(io.trino.sql.tree.LikePredicate) Test(org.testng.annotations.Test)

Example 30 with StringLiteral

use of io.trino.sql.tree.StringLiteral in project trino by trinodb.

the class TestStageStateMachine method createValuesPlan.

private static PlanFragment createValuesPlan() {
    Symbol symbol = new Symbol("column");
    PlanNodeId valuesNodeId = new PlanNodeId("plan");
    PlanFragment planFragment = new PlanFragment(new PlanFragmentId("plan"), new ValuesNode(valuesNodeId, ImmutableList.of(symbol), ImmutableList.of(new Row(ImmutableList.of(new StringLiteral("foo"))))), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(valuesNodeId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());
    return planFragment;
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) ValuesNode(io.trino.sql.planner.plan.ValuesNode) StringLiteral(io.trino.sql.tree.StringLiteral) Symbol(io.trino.sql.planner.Symbol) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) Row(io.trino.sql.tree.Row) PlanFragment(io.trino.sql.planner.PlanFragment)

Aggregations

StringLiteral (io.trino.sql.tree.StringLiteral)56 FunctionCall (io.trino.sql.tree.FunctionCall)25 LongLiteral (io.trino.sql.tree.LongLiteral)24 Test (org.junit.jupiter.api.Test)24 Test (org.testng.annotations.Test)19 Identifier (io.trino.sql.tree.Identifier)17 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)13 Expression (io.trino.sql.tree.Expression)12 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)9 AllColumns (io.trino.sql.tree.AllColumns)9 BooleanLiteral (io.trino.sql.tree.BooleanLiteral)9 Property (io.trino.sql.tree.Property)9 Cast (io.trino.sql.tree.Cast)8 SymbolReference (io.trino.sql.tree.SymbolReference)8 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)7 QualifiedName (io.trino.sql.tree.QualifiedName)7 QueryUtil.simpleQuery (io.trino.sql.QueryUtil.simpleQuery)6 CreateTable (io.trino.sql.tree.CreateTable)6 DoubleLiteral (io.trino.sql.tree.DoubleLiteral)6 GenericLiteral (io.trino.sql.tree.GenericLiteral)6