use of com.datastax.oss.dsbulk.mapping.CQLWord in project dsbulk by datastax.
the class DefaultRecordMapper method bindStatement.
private MappedBoundStatement bindStatement(Record record, PreparedStatement insertStatement) {
BoundStatementBuilder builder = boundStatementBuilderFactory.apply(insertStatement);
ColumnDefinitions variableDefinitions = insertStatement.getVariableDefinitions();
for (Field field : record.fields()) {
Set<CQLWord> variables = mapping.fieldToVariables(field);
for (CQLWord variable : variables) {
CqlIdentifier name = variable.asIdentifier();
if (size == 1 || variableDefinitions.contains(name)) {
DataType cqlType = variableDefinitions.get(name).getType();
GenericType<?> fieldType = recordMetadata.getFieldType(field, cqlType);
Object raw = record.getFieldValue(field);
builder = bindColumn(builder, field, variable, raw, cqlType, fieldType);
}
}
}
ensurePrimaryKeySet(builder);
if (protocolVersion.getCode() < DefaultProtocolVersion.V4.getCode()) {
ensureAllVariablesSet(builder, insertStatement);
}
BoundStatement bs = builder.build();
return new MappedBoundStatement(record, bs);
}
use of com.datastax.oss.dsbulk.mapping.CQLWord in project dsbulk by datastax.
the class QueryInspector method visitUsingTimestamp.
@Nullable
private CQLWord visitUsingTimestamp(IntValueContext intValueContext) {
if (intValueContext.noncolIdent() != null) {
CQLWord variable = visitNoncolIdent(intValueContext.noncolIdent());
writeTimeVariablesBuilder.add(variable);
usingTimestampVariable = variable;
} else if (intValueContext.QMARK() != null) {
writeTimeVariablesBuilder.add(INTERNAL_TIMESTAMP_VARNAME);
usingTimestampVariable = INTERNAL_TIMESTAMP_VARNAME;
}
return usingTimestampVariable;
}
use of com.datastax.oss.dsbulk.mapping.CQLWord 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;
}
Aggregations