Search in sources :

Example 6 with StringLiteral

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

the class TestSetTimeZoneTask method testSetTimeZoneIntervalDayTimeTypeInvalidFunctionCall.

@Test
public void testSetTimeZoneIntervalDayTimeTypeInvalidFunctionCall() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE parse_duration('3601s')");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 24), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 24), "parse_duration", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 39), "3601s")))));
    assertThatThrownBy(() -> executeSetTimeZone(setTimeZone, stateMachine)).isInstanceOf(TrinoException.class).hasMessage("Invalid time zone offset interval: interval contains seconds");
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) TrinoException(io.trino.spi.TrinoException) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 7 with StringLiteral

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

the class TestSetTimeZoneTask method testSetTimeZoneVarcharFunctionCall.

@Test
public void testSetTimeZoneVarcharFunctionCall() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE concat_ws('/', 'America', 'Los_Angeles')");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 15), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 15), "concat_ws", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 25), "/"), new StringLiteral(new NodeLocation(1, 30), "America"), new StringLiteral(new NodeLocation(1, 41), "Los_Angeles")))));
    executeSetTimeZone(setTimeZone, stateMachine);
    Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
    assertThat(setSessionProperties).hasSize(1);
    assertEquals(setSessionProperties.get(TIME_ZONE_ID), "America/Los_Angeles");
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 8 with StringLiteral

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

the class TestSetTimeZoneTask method testSetTimeZoneIntervalDayTimeTypeFunctionCall.

@Test
public void testSetTimeZoneIntervalDayTimeTypeFunctionCall() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE parse_duration('8h')");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 24), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 24), "parse_duration", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 39), "8h")))));
    executeSetTimeZone(setTimeZone, stateMachine);
    Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
    assertThat(setSessionProperties).hasSize(1);
    assertEquals(setSessionProperties.get(TIME_ZONE_ID), "+08:00");
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 9 with StringLiteral

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

the class TestSetPropertiesTask method testSetMaterializedViewProperties.

@Test
public void testSetMaterializedViewProperties() {
    QualifiedObjectName materializedViewName = qualifiedObjectName("test_materialized_view");
    metadata.createMaterializedView(testSession, materializedViewName, someMaterializedView(), false, false);
    // set all properties to non-DEFAULT values and check the results
    executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME), new LongLiteral("111")), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME), new StringLiteral("abc")))));
    assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_1_NAME, 111L, MATERIALIZED_VIEW_PROPERTY_2_NAME, "abc"));
    // set all properties to DEFAULT and check the results
    executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME)), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME)))));
    // since the default value of property 1 is null, property 1 should not appear in the result, whereas property 2 should appear in
    // the result with its (non-null) default value
    assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_2_NAME, MATERIALIZED_VIEW_PROPERTY_2_DEFAULT_VALUE));
}
Also used : Identifier(io.trino.sql.tree.Identifier) SetProperties(io.trino.sql.tree.SetProperties) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) Property(io.trino.sql.tree.Property) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 10 with StringLiteral

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

the class TestSetSessionTask method testSetSessionWithParameters.

@Test
public void testSetSessionWithParameters() {
    FunctionCall functionCall = new TestingFunctionResolution(transactionManager, plannerContext).functionCallBuilder(QualifiedName.of("concat")).addArgument(VARCHAR, new StringLiteral("ban")).addArgument(VARCHAR, new Parameter(0)).build();
    testSetSessionWithParameters("bar", functionCall, "banana", ImmutableList.of(new StringLiteral("ana")));
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) StringLiteral(io.trino.sql.tree.StringLiteral) Parameter(io.trino.sql.tree.Parameter) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

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