private static SelectionColumnMapping collectColumnMappings(CFMetaData cfm, List<RawSelector> rawSelectors, SelectorFactories factories) { SelectionColumnMapping selectionColumns = SelectionColumnMapping.newMapping(); Iterator<RawSelector> iter = rawSelectors.iterator(); for (Selector.Factory factory : factories) { ColumnSpecification colSpec = factory.getColumnSpecification(cfm); ColumnIdentifier alias = iter.next().alias; factory.addColumnMapping(selectionColumns, alias == null ? colSpec : colSpec.withAlias(alias)); } return selectionColumns; }
public void addFunctionsTo(List<Function> functions) { factories.forEach(p -> p.addFunctionsTo(functions)); }
protected String getColumnName() { return String.format("%s.%s", factory.getColumnName(), type.fieldName(field)); }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { Selector.Factory factory = selected.newSelectorFactory(cfm, null, defs, boundNames); AbstractType<?> type = factory.getColumnSpecification(cfm).type; if (!type.isUDT()) { throw new InvalidRequestException( String.format("Invalid field selection: %s of type %s is not a user type", selected, type.asCQL3Type())); } UserType ut = (UserType) type; int fieldIndex = ut.fieldPosition(field); if (fieldIndex == -1) { throw new InvalidRequestException(String.format("%s of type %s has no field %s", selected, type.asCQL3Type(), field)); } return FieldSelector.newFactory(ut, fieldIndex, factory); }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { Selector.Factory factory = selected.newSelectorFactory(cfm, null, defs, boundNames); AbstractType<?> type = factory.getColumnSpecification(cfm).type; if (!type.isUDT()) { throw new InvalidRequestException( String.format("Invalid field selection: %s of type %s is not a user type", selected, type.asCQL3Type())); } UserType ut = (UserType) type; int fieldIndex = ut.fieldPosition(field); if (fieldIndex == -1) { throw new InvalidRequestException(String.format("%s of type %s has no field %s", selected, type.asCQL3Type(), field)); } return FieldSelector.newFactory(ut, fieldIndex, factory); }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { Selector.Factory factory = selected.newSelectorFactory(cfm, null, defs, boundNames); AbstractType<?> type = factory.getColumnSpecification(cfm).type; if (!type.isUDT()) { throw new InvalidRequestException( String.format("Invalid field selection: %s of type %s is not a user type", selected, type.asCQL3Type())); } UserType ut = (UserType) type; int fieldIndex = ut.fieldPosition(field); if (fieldIndex == -1) { throw new InvalidRequestException(String.format("%s of type %s has no field %s", selected, type.asCQL3Type(), field)); } return FieldSelector.newFactory(ut, fieldIndex, factory); }
private SelectorFactories(List<Selectable> selectables, List<AbstractType<?>> expectedTypes, CFMetaData cfm, List<ColumnDefinition> defs, VariableSpecifications boundNames) throws InvalidRequestException { factories = new ArrayList<>(selectables.size()); for (int i = 0; i < selectables.size(); i++) { Selectable selectable = selectables.get(i); AbstractType<?> expectedType = expectedTypes == null ? null : expectedTypes.get(i); Factory factory = selectable.newSelectorFactory(cfm, expectedType, defs, boundNames); containsWritetimeFactory |= factory.isWritetimeSelectorFactory(); containsTTLFactory |= factory.isTTLSelectorFactory(); if (factory.isAggregateSelectorFactory()) ++numberOfAggregateFactories; factories.add(factory); } }
private SelectorFactories(List<Selectable> selectables, List<AbstractType<?>> expectedTypes, CFMetaData cfm, List<ColumnDefinition> defs, VariableSpecifications boundNames) throws InvalidRequestException { factories = new ArrayList<>(selectables.size()); for (int i = 0; i < selectables.size(); i++) { Selectable selectable = selectables.get(i); AbstractType<?> expectedType = expectedTypes == null ? null : expectedTypes.get(i); Factory factory = selectable.newSelectorFactory(cfm, expectedType, defs, boundNames); containsWritetimeFactory |= factory.isWritetimeSelectorFactory(); containsTTLFactory |= factory.isTTLSelectorFactory(); if (factory.isAggregateSelectorFactory()) ++numberOfAggregateFactories; factories.add(factory); } }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { List<Selectable> args = Collections.singletonList(arg); SelectorFactories factories = SelectorFactories.createFactoriesAndCollectColumnDefinitions(args, null, cfm, defs, boundNames); Selector.Factory factory = factories.get(0); // If the user is trying to cast a type on its own type we simply ignore it. if (type.getType().equals(factory.getReturnType())) return factory; FunctionName name = FunctionName.nativeFunction(CastFcts.getFunctionName(type)); Function fun = FunctionResolver.get(cfm.ksName, name, args, cfm.ksName, cfm.cfName, null); if (fun == null) { throw new InvalidRequestException(String.format("%s cannot be cast to %s", defs.get(0).name, type)); } return AbstractFunctionSelector.newFactory(fun, factories); }
private SelectorFactories(List<Selectable> selectables, List<AbstractType<?>> expectedTypes, CFMetaData cfm, List<ColumnDefinition> defs, VariableSpecifications boundNames) throws InvalidRequestException { factories = new ArrayList<>(selectables.size()); for (int i = 0; i < selectables.size(); i++) { Selectable selectable = selectables.get(i); AbstractType<?> expectedType = expectedTypes == null ? null : expectedTypes.get(i); Factory factory = selectable.newSelectorFactory(cfm, expectedType, defs, boundNames); containsWritetimeFactory |= factory.isWritetimeSelectorFactory(); containsTTLFactory |= factory.isTTLSelectorFactory(); if (factory.isAggregateSelectorFactory()) ++numberOfAggregateFactories; factories.add(factory); } }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { List<Selectable> args = Collections.singletonList(arg); SelectorFactories factories = SelectorFactories.createFactoriesAndCollectColumnDefinitions(args, null, cfm, defs, boundNames); Selector.Factory factory = factories.get(0); // If the user is trying to cast a type on its own type we simply ignore it. if (type.getType().equals(factory.getReturnType())) return factory; FunctionName name = FunctionName.nativeFunction(CastFcts.getFunctionName(type)); Function fun = FunctionResolver.get(cfm.ksName, name, args, cfm.ksName, cfm.cfName, null); if (fun == null) { throw new InvalidRequestException(String.format("%s cannot be cast to %s", defs.get(0).name, type)); } return AbstractFunctionSelector.newFactory(fun, factories); }
public Selector.Factory newSelectorFactory(CFMetaData cfm, AbstractType<?> expectedType, List<ColumnDefinition> defs, VariableSpecifications boundNames) { List<Selectable> args = Collections.singletonList(arg); SelectorFactories factories = SelectorFactories.createFactoriesAndCollectColumnDefinitions(args, null, cfm, defs, boundNames); Selector.Factory factory = factories.get(0); // If the user is trying to cast a type on its own type we simply ignore it. if (type.getType().equals(factory.getReturnType())) return factory; FunctionName name = FunctionName.nativeFunction(CastFcts.getFunctionName(type)); Function fun = FunctionResolver.get(cfm.ksName, name, args, cfm.ksName, cfm.cfName, null); if (fun == null) { throw new InvalidRequestException(String.format("%s cannot be cast to %s", defs.get(0).name, type)); } return AbstractFunctionSelector.newFactory(fun, factories); }
private static SelectionColumnMapping collectColumnMappings(CFMetaData cfm, List<RawSelector> rawSelectors, SelectorFactories factories) { SelectionColumnMapping selectionColumns = SelectionColumnMapping.newMapping(); Iterator<RawSelector> iter = rawSelectors.iterator(); for (Selector.Factory factory : factories) { ColumnSpecification colSpec = factory.getColumnSpecification(cfm); ColumnIdentifier alias = iter.next().alias; factory.addColumnMapping(selectionColumns, alias == null ? colSpec : colSpec.withAlias(alias)); } return selectionColumns; }
/** * Returns the column specification corresponding to the output value of the selector instances created by * this factory. * * @param cfm the column family meta data * @return a column specification */ public final ColumnSpecification getColumnSpecification(CFMetaData cfm) { return new ColumnSpecification(cfm.ksName, cfm.cfName, new ColumnIdentifier(getColumnName(), true), // note that the name is not necessarily // a true column name so we shouldn't intern it getReturnType()); }
public Selector newInstance(QueryOptions options) throws InvalidRequestException { return new FieldSelector(type, field, factory.newInstance(options)); }
protected void addColumnMapping(SelectionColumnMapping mapping, ColumnSpecification resultsColumn) { factory.addColumnMapping(mapping, resultsColumn); }
protected void addColumnMapping(SelectionColumnMapping mapping, ColumnSpecification resultsColumn) { SelectionColumnMapping tmpMapping = SelectionColumnMapping.newMapping(); for (Factory factory : factories) factory.addColumnMapping(tmpMapping, resultsColumn); if (tmpMapping.getMappings().get(resultsColumn).isEmpty()) // add a null mapping for cases where there are no // further selectors, such as no-arg functions and count mapping.addMapping(resultsColumn, (ColumnDefinition)null); else // collate the mapped columns from the child factories & add those mapping.addMapping(resultsColumn, tmpMapping.getMappings().values()); }
/** * Returns the column specification corresponding to the output value of the selector instances created by * this factory. * * @param cfm the column family meta data * @return a column specification */ public final ColumnSpecification getColumnSpecification(CFMetaData cfm) { return new ColumnSpecification(cfm.ksName, cfm.cfName, new ColumnIdentifier(getColumnName(), true), // note that the name is not necessarily // a true column name so we shouldn't intern it getReturnType()); }
/** * Returns the column specification corresponding to the output value of the selector instances created by * this factory. * * @param cfm the column family meta data * @return a column specification */ public final ColumnSpecification getColumnSpecification(CFMetaData cfm) { return new ColumnSpecification(cfm.ksName, cfm.cfName, new ColumnIdentifier(getColumnName(), true), // note that the name is not necessarily // a true column name so we shouldn't intern it getReturnType()); }
public void addFunctionsTo(List<Function> functions) { factories.forEach(p -> p.addFunctionsTo(functions)); }