use of io.crate.action.sql.SessionContext in project crate by crate.
the class CreateTableStatementAnalyzer method analyze.
public CreateTableAnalyzedStatement analyze(CreateTable createTable, ParameterContext parameterContext, SessionContext sessionContext) {
CreateTableAnalyzedStatement statement = new CreateTableAnalyzedStatement();
Row parameters = parameterContext.parameters();
TableIdent tableIdent = getTableIdent(createTable, sessionContext);
statement.table(tableIdent, createTable.ifNotExists(), schemas);
// apply default in case it is not specified in the genericProperties,
// if it is it will get overwritten afterwards.
TablePropertiesAnalyzer.analyze(statement.tableParameter(), new TableParameterInfo(), createTable.properties(), parameters, true);
AnalyzedTableElements tableElements = TableElementsAnalyzer.analyze(createTable.tableElements(), parameters, fulltextAnalyzerResolver, null);
// validate table elements
tableElements.finalizeAndValidate(tableIdent, Collections.emptyList(), functions, parameterContext, sessionContext);
// update table settings
statement.tableParameter().settingsBuilder().put(tableElements.settings());
statement.tableParameter().settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numberOfShards.defaultNumberOfShards());
Context context = new Context(statement, parameterContext);
statement.analyzedTableElements(tableElements);
for (CrateTableOption option : createTable.crateTableOptions()) {
process(option, context);
}
return statement;
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class CreateAlterTableStatementAnalyzerTest method testExplicitSchemaHasPrecedenceOverDefaultSchema.
@Test
public void testExplicitSchemaHasPrecedenceOverDefaultSchema() throws Exception {
CreateTableAnalyzedStatement statement = (CreateTableAnalyzedStatement) e.analyzer.boundAnalyze(SqlParser.createStatement("create table foo.bar (x string)"), new SessionContext(0, Option.NONE, "hoschi"), new ParameterContext(Row.EMPTY, Collections.<Row>emptyList())).analyzedStatement();
// schema from statement must take precedence
assertThat(statement.tableIdent().schema(), is("foo"));
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class CurrentSchemaFunctionTest method testNormalizeCurrentSchemaCustomSchema.
@Test
public void testNormalizeCurrentSchemaCustomSchema() throws Exception {
sqlExpressions = new SqlExpressions(tableSources, new SessionContext(0, Option.NONE, "custom_schema"));
functions = sqlExpressions.getInstance(Functions.class);
assertNormalize("current_schema()", isLiteral("custom_schema"), false);
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class ExpressionAnalyzerTest method testQuotedSubscriptExpression.
@Test
public void testQuotedSubscriptExpression() throws Exception {
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, new SessionContext(0, EnumSet.of(Option.ALLOW_QUOTED_SUBSCRIPT), null), paramTypeHints, new FullQualifedNameFieldProvider(dummySources), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
Field field1 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("obj['x']"), expressionAnalysisContext);
Field field2 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"obj['x']\""), expressionAnalysisContext);
assertEquals(field1, field2);
Field field3 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"myObj['x']\""), expressionAnalysisContext);
assertEquals("myObj['x']", field3.path().toString());
Field field4 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"myObj['x']['AbC']\""), expressionAnalysisContext);
assertEquals("myObj['x']['AbC']", field4.path().toString());
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class SetSessionPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, params, subQueryResults);
SessionContext sessionContext = plannerContext.transactionContext().sessionContext();
Assignment<Symbol> assignment = settings.get(0);
String settingName = eval.apply(assignment.columnName()).toString();
validateSetting(settingName);
SessionSetting<?> sessionSetting = sessionSettingRegistry.settings().get(settingName);
if (sessionSetting == null) {
LOGGER.info("SET SESSION STATEMENT WILL BE IGNORED: {}", settingName);
} else {
sessionSetting.apply(sessionContext, assignment.expressions(), eval);
}
consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
}
Aggregations