use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class QueryKeyExtractorTest method testDuplicateFullQuery.
@Test
public void testDuplicateFullQuery() throws Exception {
// Build 1st Table
NamespaceConfig testNamespace = NamespaceConfig.builder().name("namespace1").build();
NamespacePackage testNamespacePackage = new NamespacePackage(testNamespace);
Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace1").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
TableType testType = new TableType(testTable, testNamespacePackage);
dictionary.bindEntity(testType);
SQLTable testSqlTable = new SQLTable(new Namespace(testNamespacePackage), testType, dictionary);
// Build 2nd Table
NamespaceConfig anotherTestNamespace = NamespaceConfig.builder().name("namespace2").build();
NamespacePackage anotherTestNamespacePackage = new NamespacePackage(anotherTestNamespace);
Table anotherTestTable = // Exactly same as testTable but different namespace
Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace2").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
TableType anotherTestType = new TableType(anotherTestTable, anotherTestNamespacePackage);
dictionary.bindEntity(anotherTestType);
SQLTable anotherTestSqlTable = new SQLTable(new Namespace(anotherTestNamespacePackage), anotherTestType, dictionary);
// Build Query and Test
Query query = Query.builder().source(testSqlTable).dimensionProjection(testSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
assertEquals(// table name
"namespace1_Table;" + // metrics
"{}" + // Group by
"{dim1;{}}" + // time dimensions
"{}" + // where
";" + // having
";" + // sort
";" + // pagination
"{0;2;1;}", QueryKeyExtractor.extractKey(query));
Query anotherQuery = Query.builder().source(anotherTestSqlTable).dimensionProjection(anotherTestSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
assertEquals(// table name
"namespace2_Table;" + // metrics
"{}" + // Group by
"{dim1;{}}" + // time dimensions
"{}" + // where
";" + // having
";" + // sort
";" + // pagination
"{0;2;1;}", QueryKeyExtractor.extractKey(anotherQuery));
assertNotEquals(QueryKeyExtractor.extractKey(anotherQuery), QueryKeyExtractor.extractKey(query));
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class AggregationDataStoreTransactionTest method testMissingRequiredColumnFilter.
@Test
public void testMissingRequiredColumnFilter() throws Exception {
Type<PlayerStatsWithRequiredFilter> tableType = ClassType.of(PlayerStatsWithRequiredFilter.class);
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
SQLTable table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), tableType, dictionary);
Query query = Query.builder().column(SQLMetricProjection.builder().name("highScore").build()).source(table).build();
AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
assertThrows(BadRequestException.class, () -> tx.addColumnFilterArguments(table, query, dictionary));
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class DefaultQueryValidatorTest method testMissingRequiredParameterInProjection.
@Test
public void testMissingRequiredParameterInProjection() {
SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
Query query = Query.builder().source(source).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName")).build();
validateQuery(query, "Invalid operation: Argument 'format' for column 'countryName' is required");
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class DefaultQueryValidatorTest method testQueryingByIdAlone.
@Test
public void testQueryingByIdAlone() {
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("id")).build();
validateQuery(query, "Invalid operation: Cannot query a table only by ID");
}
use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.
the class Slf4jQueryLoggerTest method testAccept.
@Test
void testAccept() {
Slf4jQueryLogger.Logger logger = (template, node) -> {
assertEquals("QUERY ACCEPTED: {}", template);
assertEquals("{\"id\":\"edc4a871-dff2-4054-804e-d80075cf828d\",\"user\":\"Unknown\",\"apiVersion\":\"1.0\",\"path\":\"/sales\",\"headers\":{\"Content-Type\":\"application/vnd.api+json\"}}", node.toString());
};
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/vnd.api+json");
Slf4jQueryLogger slf4jQueryLogger = new Slf4jQueryLogger(logger);
slf4jQueryLogger.acceptQuery(UUID.fromString("edc4a871-dff2-4054-804e-d80075cf828d"), new User(null), headers, "1.0", new MultivaluedHashMap<>(), "/sales");
}
Aggregations