use of io.crate.sql.tree.Statement in project crate by crate.
the class Session method analyze.
public void analyze(String statementName, Statement statement, List<DataType> paramTypes, @Nullable String query) {
AnalyzedStatement analyzedStatement;
DataType[] parameterTypes;
try {
analyzedStatement = analyzer.analyze(statement, sessionContext, new ParamTypeHints(paramTypes));
parameterTypes = parameterTypeExtractor.getParameterTypes(x -> Relations.traverseDeepSymbols(analyzedStatement, x));
} catch (Throwable t) {
jobsLogs.logPreExecutionFailure(UUIDs.dirtyUUID(), query == null ? statementName : query, SQLExceptions.messageOf(t), sessionContext.sessionUser());
throw t;
}
preparedStatements.put(statementName, new PreparedStmt(statement, analyzedStatement, query, parameterTypes));
}
use of io.crate.sql.tree.Statement in project crate by crate.
the class ExplainStatementAnalyzer method analyze.
public ExplainAnalyzedStatement analyze(Explain node, Analysis analysis) {
Statement statement = node.getStatement();
statement.accept(CHECK_VISITOR, null);
final AnalyzedStatement subStatement;
ProfilingContext profilingContext;
if (node.isAnalyze()) {
profilingContext = new ProfilingContext(List.of());
Timer timer = profilingContext.createAndStartTimer(ExplainPlan.Phase.Analyze.name());
subStatement = analyzer.analyzedStatement(statement, analysis);
profilingContext.stopTimerAndStoreDuration(timer);
} else {
profilingContext = null;
subStatement = analyzer.analyzedStatement(statement, analysis);
}
String columnName = SqlFormatter.formatSql(node);
return new ExplainAnalyzedStatement(columnName, subStatement, profilingContext);
}
use of io.crate.sql.tree.Statement in project crate by crate.
the class DocIndexMetadataTest method getDocIndexMetadataFromStatement.
private DocIndexMetadata getDocIndexMetadataFromStatement(String stmt) throws IOException {
Statement statement = SqlParser.createStatement(stmt);
DocTableInfoFactory docTableInfoFactory = new InternalDocTableInfoFactory(nodeCtx, new IndexNameExpressionResolver());
ViewInfoFactory viewInfoFactory = (ident, state) -> null;
DocSchemaInfo docSchemaInfo = new DocSchemaInfo(Schemas.DOC_SCHEMA_NAME, clusterService, nodeCtx, udfService, viewInfoFactory, docTableInfoFactory);
Path homeDir = createTempDir();
Schemas schemas = new Schemas(Map.of("doc", docSchemaInfo), clusterService, new DocSchemaInfoFactory(docTableInfoFactory, viewInfoFactory, nodeCtx, udfService));
FulltextAnalyzerResolver fulltextAnalyzerResolver = new FulltextAnalyzerResolver(clusterService, new AnalysisRegistry(new Environment(Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), homeDir.toString()).build(), homeDir.resolve("config")), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(nodeCtx);
Analysis analysis = new Analysis(new CoordinatorTxnCtx(SessionContext.systemSessionContext()), ParamTypeHints.EMPTY);
CoordinatorTxnCtx txnCtx = new CoordinatorTxnCtx(SessionContext.systemSessionContext());
AnalyzedCreateTable analyzedCreateTable = analyzer.analyze((CreateTable<Expression>) statement, analysis.paramTypeHints(), analysis.transactionContext());
BoundCreateTable analyzedStatement = CreateTablePlan.bind(analyzedCreateTable, txnCtx, nodeCtx, Row.EMPTY, SubQueryResults.EMPTY, new NumberOfShards(clusterService), schemas, fulltextAnalyzerResolver);
Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(analyzedStatement.tableParameter().settings());
IndexMetadata indexMetadata = IndexMetadata.builder(analyzedStatement.tableIdent().name()).settings(settingsBuilder).putMapping(new MappingMetadata(Constants.DEFAULT_MAPPING_TYPE, analyzedStatement.mapping())).build();
return newMeta(indexMetadata, analyzedStatement.tableIdent().name());
}
Aggregations