Search in sources :

Example 1 with ParameterExpression

use of io.crate.sql.tree.ParameterExpression in project crate by crate.

the class ESClusterUpdateSettingsTaskTest method testUpdateMultipleSettingsWithParameters.

@Test
public void testUpdateMultipleSettingsWithParameters() throws Exception {
    Map<String, List<Expression>> settings = new HashMap<String, List<Expression>>() {

        {
            put("stats.operations_log_size", ImmutableList.<Expression>of(new ParameterExpression(1)));
            put("stats.jobs_log_size", ImmutableList.<Expression>of(new ParameterExpression(2)));
        }
    };
    Settings expected = Settings.builder().put("stats.operations_log_size", 10).put("stats.jobs_log_size", 25).build();
    assertThat(ESClusterUpdateSettingsTask.buildSettingsFrom(settings, new RowN(new Object[] { 10, 25 })), is(expected));
}
Also used : RowN(io.crate.data.RowN) HashMap(java.util.HashMap) ParameterExpression(io.crate.sql.tree.ParameterExpression) Expression(io.crate.sql.tree.Expression) ParameterExpression(io.crate.sql.tree.ParameterExpression) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with ParameterExpression

use of io.crate.sql.tree.ParameterExpression in project crate by crate.

the class DeleteAnalyzer method analyze.

public AnalyzedStatement analyze(Delete node, Analysis analysis) {
    int numNested = 1;
    Function<ParameterExpression, Symbol> convertParamFunction = analysis.parameterContext();
    StatementAnalysisContext statementAnalysisContext = new StatementAnalysisContext(analysis.sessionContext(), convertParamFunction, Operation.DELETE, analysis.transactionContext());
    RelationAnalysisContext relationAnalysisContext = statementAnalysisContext.startRelation();
    AnalyzedRelation analyzedRelation = relationAnalyzer.analyze(node.getRelation(), statementAnalysisContext);
    assert analyzedRelation instanceof DocTableRelation : "analyzedRelation must be DocTableRelation";
    DocTableRelation docTableRelation = (DocTableRelation) analyzedRelation;
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.MUTATE, null, docTableRelation);
    DeleteAnalyzedStatement deleteAnalyzedStatement = new DeleteAnalyzedStatement(docTableRelation);
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, analysis.sessionContext(), convertParamFunction, new FullQualifedNameFieldProvider(relationAnalysisContext.sources()), null);
    ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
    WhereClauseAnalyzer whereClauseAnalyzer = new WhereClauseAnalyzer(functions, deleteAnalyzedStatement.analyzedRelation());
    if (analysis.parameterContext().hasBulkParams()) {
        numNested = analysis.parameterContext().numBulkParams();
    }
    TransactionContext transactionContext = analysis.transactionContext();
    for (int i = 0; i < numNested; i++) {
        analysis.parameterContext().setBulkIdx(i);
        Symbol query = expressionAnalyzer.generateQuerySymbol(node.getWhere(), expressionAnalysisContext);
        WhereClause whereClause = new WhereClause(normalizer.normalize(query, transactionContext));
        whereClause = validate(whereClauseAnalyzer.analyze(whereClause, transactionContext));
        deleteAnalyzedStatement.whereClauses.add(whereClause);
    }
    statementAnalysisContext.endRelation();
    return deleteAnalyzedStatement;
}
Also used : ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) TransactionContext(io.crate.metadata.TransactionContext) ParameterExpression(io.crate.sql.tree.ParameterExpression) WhereClauseAnalyzer(io.crate.analyze.where.WhereClauseAnalyzer)

Example 3 with ParameterExpression

use of io.crate.sql.tree.ParameterExpression in project crate by crate.

the class ESClusterUpdateSettingsTaskTest method testUpdateSettingsWithInvalidTimeValue.

@Test
public void testUpdateSettingsWithInvalidTimeValue() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Invalid value for argument 'cluster.graceful_stop.timeout'");
    Map<String, List<Expression>> settings = new HashMap<String, List<Expression>>() {

        {
            put("cluster.graceful_stop.timeout", ImmutableList.<Expression>of(new ParameterExpression(1)));
        }
    };
    ESClusterUpdateSettingsTask.buildSettingsFrom(settings, new RowN(new Object[] { "-1h" }));
}
Also used : RowN(io.crate.data.RowN) HashMap(java.util.HashMap) ParameterExpression(io.crate.sql.tree.ParameterExpression) Expression(io.crate.sql.tree.Expression) ParameterExpression(io.crate.sql.tree.ParameterExpression) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

ParameterExpression (io.crate.sql.tree.ParameterExpression)3 ImmutableList (com.google.common.collect.ImmutableList)2 RowN (io.crate.data.RowN)2 Expression (io.crate.sql.tree.Expression)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 Symbol (io.crate.analyze.symbol.Symbol)1 WhereClauseAnalyzer (io.crate.analyze.where.WhereClauseAnalyzer)1 TransactionContext (io.crate.metadata.TransactionContext)1 Settings (org.elasticsearch.common.settings.Settings)1