use of com.datastax.oss.dsbulk.mapping.CQLFragment in project dsbulk by datastax.
the class SchemaSettings method columnsToVariables.
@NonNull
private Set<CQLWord> columnsToVariables(Collection<ColumnMetadata> columns) {
Map<CQLWord, CQLFragment> boundVariables = queryInspector.getAssignments();
Set<CQLWord> variables = new HashSet<>(columns.size());
for (ColumnMetadata column : columns) {
CQLFragment variable = boundVariables.get(CQLWord.fromCqlIdentifier(column.getName()));
if (variable instanceof CQLWord) {
variables.add((CQLWord) variable);
}
}
return variables;
}
use of com.datastax.oss.dsbulk.mapping.CQLFragment in project dsbulk by datastax.
the class SchemaSettings method inferFieldsToVariablesMap.
private ImmutableMultimap<MappingField, CQLFragment> inferFieldsToVariablesMap(Collection<CQLFragment> columns) {
// use a builder to preserve iteration order
ImmutableMultimap.Builder<MappingField, CQLFragment> fieldsToVariables = ImmutableMultimap.builder();
List<CQLFragment> excludedVariables = new ArrayList<>(mapping.getExcludedVariables());
if (!isCounterTable() && schemaGenerationStrategy.isMapping()) {
for (CQLWord variable : mapping.getExcludedVariables()) {
if (preserveTimestamp) {
excludedVariables.add(new FunctionCall(null, WRITETIME, variable));
}
if (preserveTtl) {
excludedVariables.add(new FunctionCall(null, TTL, variable));
}
}
}
int i = 0;
for (CQLFragment colName : columns) {
if (!excludedVariables.contains(colName)) {
if (mappingPreference == INDEXED_ONLY) {
fieldsToVariables.put(new IndexedMappingField(i), colName);
} else {
fieldsToVariables.put(new MappedMappingField(colName.render(INTERNAL)), colName);
}
}
i++;
}
return fieldsToVariables.build();
}
use of com.datastax.oss.dsbulk.mapping.CQLFragment in project dsbulk by datastax.
the class QueryInspector method visitNormalInsertStatement.
@Override
public CQLFragment visitNormalInsertStatement(NormalInsertStatementContext ctx) {
if (ctx.cident().size() != ctx.term().size()) {
throw new IllegalArgumentException(String.format("Invalid query: the number of columns to insert (%d) does not match the number of terms (%d): %s.", ctx.cident().size(), ctx.term().size(), query));
}
for (int i = 0; i < ctx.cident().size(); i++) {
CQLWord column = visitCident(ctx.cident().get(i));
CQLFragment variable = visitTerm(ctx.term().get(i));
assignmentsBuilder.put(column, variable == QUESTION_MARK ? column : variable);
}
if (ctx.usingClause() != null) {
visitUsingClause(ctx.usingClause());
}
return null;
}
use of com.datastax.oss.dsbulk.mapping.CQLFragment 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