Search in sources :

Example 1 with PathElement

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

the class SqlPath method parsePath.

private void parsePath() {
    checkState(rawPath.isPresent(), "rawPath must be present to parse");
    SqlParser parser = new SqlParser();
    List<PathElement> pathSpecification = parser.createPathSpecification(rawPath.get()).getPath();
    this.parsedPath = pathSpecification.stream().map(pathElement -> new SqlPathElement(pathElement.getCatalog(), pathElement.getSchema())).collect(toImmutableList());
}
Also used : PathElement(io.trino.sql.tree.PathElement) SqlParser(io.trino.sql.parser.SqlParser)

Example 2 with PathElement

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

the class TestSetPathTask method testSetPathInvalidCatalog.

@Test
public void testSetPathInvalidCatalog() {
    PathSpecification invalidPathSpecification = new PathSpecification(Optional.empty(), ImmutableList.of(new PathElement(Optional.of(new Identifier("invalidCatalog")), new Identifier("thisDoesNotMatter"))));
    QueryStateMachine stateMachine = createQueryStateMachine("SET PATH invalidCatalog.thisDoesNotMatter");
    assertThatThrownBy(() -> executeSetPathTask(invalidPathSpecification, stateMachine)).isInstanceOf(TrinoException.class).hasMessageMatching("Catalog '.*' does not exist");
}
Also used : Identifier(io.trino.sql.tree.Identifier) PathElement(io.trino.sql.tree.PathElement) PathSpecification(io.trino.sql.tree.PathSpecification) TrinoException(io.trino.spi.TrinoException) Test(org.testng.annotations.Test)

Example 3 with PathElement

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

the class TestSetPathTask method testSetPath.

@Test
public void testSetPath() {
    PathSpecification pathSpecification = new PathSpecification(Optional.empty(), ImmutableList.of(new PathElement(Optional.empty(), new Identifier("foo"))));
    QueryStateMachine stateMachine = createQueryStateMachine("SET PATH foo");
    executeSetPathTask(pathSpecification, stateMachine);
    assertEquals(stateMachine.getSetPath(), "foo");
}
Also used : Identifier(io.trino.sql.tree.Identifier) PathElement(io.trino.sql.tree.PathElement) PathSpecification(io.trino.sql.tree.PathSpecification) Test(org.testng.annotations.Test)

Example 4 with PathElement

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

the class TestSqlParser method testSetPath.

@Test
public void testSetPath() {
    assertStatement("SET PATH iLikeToEat.apples, andBananas", new SetPath(new PathSpecification(Optional.empty(), ImmutableList.of(new PathElement(Optional.of(new Identifier("iLikeToEat")), new Identifier("apples")), new PathElement(Optional.empty(), new Identifier("andBananas"))))));
    assertStatement("SET PATH \"schemas,with\".\"grammar.in\", \"their!names\"", new SetPath(new PathSpecification(Optional.empty(), ImmutableList.of(new PathElement(Optional.of(new Identifier("schemas,with")), new Identifier("grammar.in")), new PathElement(Optional.empty(), new Identifier("their!names"))))));
    assertThatThrownBy(() -> assertStatement("SET PATH one.too.many, qualifiers", new SetPath(new PathSpecification(Optional.empty(), ImmutableList.of(new PathElement(Optional.empty(), new Identifier("dummyValue"))))))).isInstanceOf(ParsingException.class).hasMessage("line 1:17: mismatched input '.'. Expecting: ',', <EOF>");
    assertThatThrownBy(() -> SQL_PARSER.createStatement("SET PATH ", new ParsingOptions())).isInstanceOf(ParsingException.class).hasMessage("line 1:10: mismatched input '<EOF>'. Expecting: <identifier>");
}
Also used : SetPath(io.trino.sql.tree.SetPath) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PathElement(io.trino.sql.tree.PathElement) PathSpecification(io.trino.sql.tree.PathSpecification) Test(org.junit.jupiter.api.Test)

Aggregations

PathElement (io.trino.sql.tree.PathElement)4 Identifier (io.trino.sql.tree.Identifier)3 PathSpecification (io.trino.sql.tree.PathSpecification)3 Test (org.testng.annotations.Test)2 TrinoException (io.trino.spi.TrinoException)1 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)1 SqlParser (io.trino.sql.parser.SqlParser)1 SetPath (io.trino.sql.tree.SetPath)1 Test (org.junit.jupiter.api.Test)1