use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class DefaultQueryValidatorTest method testInvalidColumnArgument.
@Test
public void testInvalidColumnArgument() {
SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
Map<String, Argument> argumentMap = new HashMap<>();
argumentMap.put("format", Argument.builder().name("format").value(";").build());
Query query = Query.builder().source(source).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName", "countryName", argumentMap)).build();
validateQuery(query, "Invalid operation: Argument 'format' for column 'countryName' must match one of these values: [lower, upper]");
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class DefaultQueryValidatorTest method testInvalidTableArgument.
@Test
public void testInvalidTableArgument() {
SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
Map<String, Argument> tableArguments = new HashMap<>();
tableArguments.put("rating", Argument.builder().name("rating").value("SELECT * FROM FOO;").build());
Map<String, Argument> columnArguments = new HashMap<>();
columnArguments.put("format", Argument.builder().name("format").value("lower").build());
Query query = Query.builder().source(source).arguments(tableArguments).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName", columnArguments)).build();
validateQuery(query, "Invalid operation: Argument 'rating' for table 'playerStatsView' has an invalid value: SELECT * FROM FOO;");
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class EntityProjectionTranslatorTest method testQueryArguments.
@Test
public void testQueryArguments() {
EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, basicProjection, scope, true);
Query query = translator.getQuery();
Argument queryArg = query.getArguments().get("foo");
assertEquals("bar", queryArg.getValue());
Argument lowScoreArg = query.getColumnProjection("lowScore").getArguments().get("foo");
assertEquals("bar", lowScoreArg.getValue());
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class ColumnArgumentValidator method verifyLogicalReference.
private void verifyLogicalReference(LogicalReference reference) {
SQLTable sqlTable = (SQLTable) reference.getSource();
ColumnProjection columnProj = reference.getColumn();
// This will have dependent column's defined arguments merged with pinned arguments used to invoke this column.
Map<String, Argument> mergedArguments = columnProj.getArguments();
Column refColumn = sqlTable.getColumn(Column.class, columnProj.getName());
verifyPinnedArguments(mergedArguments, refColumn, String.format(errorMsgPrefix + "Type mismatch of Fixed value provided for Dependent Column: '%s' in table: '%s'. ", refColumn.getName(), sqlTable.getName()));
refColumn.getArgumentDefinitions().forEach(argDef -> {
String argName = argDef.getName();
if (column.hasArgumentDefinition(argName)) {
if (argDef.getType() != column.getArgumentDefinition(argName).getType()) {
throw new IllegalStateException(String.format(errorMsgPrefix + "Argument type mismatch. Dependent Column: '%s' in table: '%s' has same" + " Argument: '%s' with type '%s'.", refColumn.getName(), sqlTable.getName(), argName, argDef.getType()));
}
} else if (StringUtils.isBlank(argDef.getDefaultValue().toString()) && StringUtils.isBlank(mergedArguments.get(argName).getValue().toString())) {
throw new IllegalStateException(String.format(errorMsgPrefix + "Argument '%s' with type '%s' is not defined but is required for" + " Dependent Column: '%s' in table: '%s'.", argName, argDef.getType(), refColumn.getName(), sqlTable.getName()));
}
});
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class SQLTimeDimensionProjection method getGrainFromArguments.
private TimeDimensionGrain getGrainFromArguments(Map<String, Argument> arguments, TimeDimension column) {
Argument grainArgument = arguments.get("grain");
if (grainArgument == null) {
return column.getDefaultGrain();
}
String grainName = grainArgument.getValue().toString().toLowerCase(Locale.ENGLISH);
return column.getSupportedGrains().stream().filter(grain -> grain.getGrain().name().toLowerCase(Locale.ENGLISH).equals(grainName)).findFirst().orElseThrow(() -> new InvalidParameterizedAttributeException(name, grainArgument));
}
Aggregations