use of com.yahoo.elide.datastores.aggregation.metadata.models.Namespace in project elide by yahoo.
the class MetaDataStoreTest method testHiddenTable.
@Test
public void testHiddenTable() {
Table player = dataStore.getTable(ClassType.of(Player.class));
Table playerStats = dataStore.getTable(ClassType.of(PlayerStats.class));
assertTrue(player.isHidden());
assertFalse(playerStats.isHidden());
Namespace namespace = dataStore.getNamespace(ClassType.of(Player.class));
assertTrue(namespace.getTables().contains(playerStats));
assertFalse(namespace.getTables().contains(player));
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Namespace 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.metadata.models.Namespace in project elide by yahoo.
the class AggregationDataStoreTransactionTest method testMissingRequiredTableFilter.
@Test
public void testMissingRequiredTableFilter() {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
Table table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), ClassType.of(PlayerStatsWithRequiredFilter.class), dictionary);
AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
assertThrows(BadRequestException.class, () -> tx.addTableFilterArguments(table, query, dictionary));
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Namespace 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.metadata.models.Namespace in project elide by yahoo.
the class MetaDataStore method getNamespace.
/**
* Get a namespace object.
*
* @param modelType the model type
* @return the namespace
*/
public Namespace getNamespace(Type<?> modelType) {
String apiVersionName = EntityDictionary.getModelVersion(modelType);
Include include = (Include) EntityDictionary.getFirstPackageAnnotation(modelType, Arrays.asList(Include.class));
String namespaceName;
if (include != null && !include.name().isEmpty()) {
namespaceName = include.name();
} else {
namespaceName = DEFAULT;
}
return namespaces.stream().filter(namespace -> namespace.getName().equals(namespaceName)).filter(namespace -> namespace.getVersion().equals(apiVersionName)).findFirst().orElse(null);
}
Aggregations