Search in sources :

Example 1 with TermContext

use of com.datastax.oss.dsbulk.generated.cql3.CqlParser.TermContext in project dsbulk by datastax.

the class QueryInspector method visitFunction.

@Override
@NonNull
public FunctionCall visitFunction(FunctionContext ctx) {
    CQLWord keyspaceName = null;
    if (ctx.functionName().keyspaceName() != null) {
        keyspaceName = visitKeyspaceName(ctx.functionName().keyspaceName());
    }
    CQLWord functionName = visitAllowedFunctionName(ctx.functionName().allowedFunctionName());
    List<CQLFragment> args = new ArrayList<>();
    if (ctx.functionArgs() != null) {
        for (TermContext arg : ctx.functionArgs().term()) {
            CQLFragment term = visitTerm(arg);
            if (term == QUESTION_MARK) {
                throw new IllegalArgumentException(String.format("Invalid query: positional variables are not allowed as function parameters: %s.", query));
            }
            args.add(term);
        }
    }
    return new FunctionCall(keyspaceName, functionName, args);
}
Also used : ArrayList(java.util.ArrayList) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) CQLFragment(com.datastax.oss.dsbulk.mapping.CQLFragment) FunctionCall(com.datastax.oss.dsbulk.mapping.FunctionCall) TermContext(com.datastax.oss.dsbulk.generated.cql3.CqlParser.TermContext) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 2 with TermContext

use of com.datastax.oss.dsbulk.generated.cql3.CqlParser.TermContext in project dsbulk by datastax.

the class QueryInspector method visitRelation.

// WHERE clause
@Override
@Nullable
public CQLFragment visitRelation(RelationContext ctx) {
    // relation contains another relation: drill down
    while (ctx.relation() != null) {
        ctx = ctx.relation();
    }
    // myCol = :myVar or myCol = ?
    if (ctx.getChildCount() == 3 && ctx.getChild(0) instanceof CidentContext && ctx.getChild(1) instanceof RelationTypeContext && ctx.getChild(2) instanceof TermContext && ctx.getChild(1).getText().equals("=")) {
        CQLWord column = visitCident(ctx.cident());
        if (column.equals(SOLR_QUERY)) {
            hasSearchClause = true;
        }
        CQLFragment variable = visitTerm(ctx.term().get(0));
        assignmentsBuilder.put(column, variable.equals(QUESTION_MARK) ? column : variable);
    } else if (ctx.K_TOKEN() != null) {
        CQLFragment variable = visitTerm(ctx.term().get(0));
        if (variable instanceof CQLWord) {
            if (variable == QUESTION_MARK) {
                variable = INTERNAL_TOKEN_VARNAME;
            }
            if (ctx.relationType().getText().equals(">")) {
                tokenRangeRestrictionStartVariable = (CQLWord) variable;
                tokenRangeRestrictionStartVariableIndex = tokenRangeRestrictionVariableIndex++;
            } else if (ctx.relationType().getText().equals("<=")) {
                tokenRangeRestrictionEndVariable = (CQLWord) variable;
                tokenRangeRestrictionEndVariableIndex = tokenRangeRestrictionVariableIndex++;
            }
        }
    }
    // other relation types: unsupported
    return null;
}
Also used : CidentContext(com.datastax.oss.dsbulk.generated.cql3.CqlParser.CidentContext) RelationTypeContext(com.datastax.oss.dsbulk.generated.cql3.CqlParser.RelationTypeContext) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) CQLFragment(com.datastax.oss.dsbulk.mapping.CQLFragment) TermContext(com.datastax.oss.dsbulk.generated.cql3.CqlParser.TermContext) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Aggregations

TermContext (com.datastax.oss.dsbulk.generated.cql3.CqlParser.TermContext)2 CQLFragment (com.datastax.oss.dsbulk.mapping.CQLFragment)2 CQLWord (com.datastax.oss.dsbulk.mapping.CQLWord)2 CidentContext (com.datastax.oss.dsbulk.generated.cql3.CqlParser.CidentContext)1 RelationTypeContext (com.datastax.oss.dsbulk.generated.cql3.CqlParser.RelationTypeContext)1 FunctionCall (com.datastax.oss.dsbulk.mapping.FunctionCall)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 ArrayList (java.util.ArrayList)1