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());
}
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();
}
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();
}
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);
}
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"))));
}
Aggregations