Search in sources :

Example 1 with SqlParser

use of io.trino.sql.parser.SqlParser 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 SqlParser

use of io.trino.sql.parser.SqlParser in project trino by trinodb.

the class HttpRequestSessionContextFactory method parsePreparedStatementsHeaders.

private Map<String, String> parsePreparedStatementsHeaders(ProtocolHeaders protocolHeaders, MultivaluedMap<String, String> headers) {
    ImmutableMap.Builder<String, String> preparedStatements = ImmutableMap.builder();
    parseProperty(headers, protocolHeaders.requestPreparedStatement()).forEach((key, value) -> {
        String statementName;
        try {
            statementName = urlDecode(key);
        } catch (IllegalArgumentException e) {
            throw badRequest(format("Invalid %s header: %s", protocolHeaders.requestPreparedStatement(), e.getMessage()));
        }
        String sqlString = preparedStatementEncoder.decodePreparedStatementFromHeader(value);
        // Validate statement
        SqlParser sqlParser = new SqlParser();
        try {
            sqlParser.createStatement(sqlString, new ParsingOptions(AS_DOUBLE));
        } catch (ParsingException e) {
            throw badRequest(format("Invalid %s header: %s", protocolHeaders.requestPreparedStatement(), e.getMessage()));
        }
        preparedStatements.put(statementName, sqlString);
    });
    return preparedStatements.buildOrThrow();
}
Also used : ParsingOptions(io.trino.sql.parser.ParsingOptions) ParsingException(io.trino.sql.parser.ParsingException) SqlParser(io.trino.sql.parser.SqlParser) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 3 with SqlParser

use of io.trino.sql.parser.SqlParser in project trino by trinodb.

the class TestPrepareTask method executePrepare.

private Map<String, String> executePrepare(String statementName, Statement statement, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControl = new AccessControlManager(transactionManager, emptyEventListenerManager(), new AccessControlConfig(), DefaultSystemAccessControl.NAME);
    accessControl.setSystemAccessControls(List.of(AllowAllSystemAccessControl.INSTANCE));
    QueryStateMachine stateMachine = QueryStateMachine.begin(Optional.empty(), sqlString, Optional.empty(), session, URI.create("fake://uri"), new ResourceGroupId("test"), false, transactionManager, accessControl, executor, metadata, WarningCollector.NOOP, Optional.empty());
    Prepare prepare = new Prepare(identifier(statementName), statement);
    new PrepareTask(new SqlParser()).execute(prepare, stateMachine, emptyList(), WarningCollector.NOOP);
    return stateMachine.getAddedPreparedStatements();
}
Also used : AccessControlManager(io.trino.security.AccessControlManager) AccessControlConfig(io.trino.security.AccessControlConfig) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager) SqlParser(io.trino.sql.parser.SqlParser) Prepare(io.trino.sql.tree.Prepare)

Example 4 with SqlParser

use of io.trino.sql.parser.SqlParser in project trino by trinodb.

the class TestCreateViewTask method setUp.

@Override
@BeforeMethod
public void setUp() {
    super.setUp();
    parser = new SqlParser();
    analyzerFactory = new AnalyzerFactory(createTestingStatementAnalyzerFactory(plannerContext, new AllowAllAccessControl(), new TablePropertyManager(), new AnalyzePropertyManager()), new StatementRewrite(ImmutableSet.of()));
    QualifiedObjectName tableName = qualifiedObjectName("mock_table");
    metadata.createTable(testSession, CATALOG_NAME, someTable(tableName), false);
}
Also used : AllowAllAccessControl(io.trino.security.AllowAllAccessControl) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) SqlParser(io.trino.sql.parser.SqlParser) TablePropertyManager(io.trino.metadata.TablePropertyManager) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with SqlParser

use of io.trino.sql.parser.SqlParser in project trino by trinodb.

the class TestPatternRecognitionNodeSerialization method testExpressionAndValuePointersRoundtrip.

@Test
public void testExpressionAndValuePointersRoundtrip() {
    ObjectMapperProvider provider = new ObjectMapperProvider();
    provider.setJsonSerializers(ImmutableMap.of(Expression.class, new ExpressionSerialization.ExpressionSerializer()));
    provider.setJsonDeserializers(ImmutableMap.of(Expression.class, new ExpressionSerialization.ExpressionDeserializer(new SqlParser())));
    JsonCodec<ExpressionAndValuePointers> codec = new JsonCodecFactory(provider).jsonCodec(ExpressionAndValuePointers.class);
    assertJsonRoundTrip(codec, new ExpressionAndValuePointers(new NullLiteral(), ImmutableList.of(), ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of()));
    assertJsonRoundTrip(codec, new ExpressionAndValuePointers(new IfExpression(new ComparisonExpression(GREATER_THAN, new SymbolReference("classifier"), new SymbolReference("x")), new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()), new ArithmeticUnaryExpression(MINUS, new SymbolReference("match_number"))), ImmutableList.of(new Symbol("classifier"), new Symbol("x"), new Symbol("match_number")), ImmutableList.of(new ScalarValuePointer(new LogicalIndexPointer(ImmutableSet.of(new IrLabel("A"), new IrLabel("B")), false, true, 1, -1), new Symbol("input_symbol_a")), new ScalarValuePointer(new LogicalIndexPointer(ImmutableSet.of(new IrLabel("B")), true, false, 2, 1), new Symbol("input_symbol_a")), new ScalarValuePointer(new LogicalIndexPointer(ImmutableSet.of(), true, true, 0, 0), new Symbol("input_symbol_a"))), ImmutableSet.of(new Symbol("classifier")), ImmutableSet.of(new Symbol("match_number"))));
}
Also used : IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) IfExpression(io.trino.sql.tree.IfExpression) ScalarValuePointer(io.trino.sql.planner.rowpattern.ScalarValuePointer) SymbolReference(io.trino.sql.tree.SymbolReference) Symbol(io.trino.sql.planner.Symbol) SqlParser(io.trino.sql.parser.SqlParser) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) ExpressionAndValuePointers(io.trino.sql.planner.rowpattern.LogicalIndexExtractor.ExpressionAndValuePointers) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) LogicalIndexPointer(io.trino.sql.planner.rowpattern.LogicalIndexPointer) FunctionCall(io.trino.sql.tree.FunctionCall) JsonCodecFactory(io.airlift.json.JsonCodecFactory) NullLiteral(io.trino.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Aggregations

SqlParser (io.trino.sql.parser.SqlParser)14 Test (org.testng.annotations.Test)7 Expression (io.trino.sql.tree.Expression)6 JsonCodecFactory (io.airlift.json.JsonCodecFactory)4 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 Duration (io.airlift.units.Duration)3 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)3 QueryUtil.simpleQuery (io.trino.sql.QueryUtil.simpleQuery)3 AnalyzerFactory (io.trino.sql.analyzer.AnalyzerFactory)3 Symbol (io.trino.sql.planner.Symbol)3 ExpressionAndValuePointers (io.trino.sql.planner.rowpattern.LogicalIndexExtractor.ExpressionAndValuePointers)3 IrLabel (io.trino.sql.planner.rowpattern.ir.IrLabel)3 ArithmeticUnaryExpression (io.trino.sql.tree.ArithmeticUnaryExpression)3 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)3 IfExpression (io.trino.sql.tree.IfExpression)3 NullLiteral (io.trino.sql.tree.NullLiteral)3 Futures.immediateVoidFuture (com.google.common.util.concurrent.Futures.immediateVoidFuture)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Session (io.trino.Session)2