Search in sources :

Example 1 with Namespace

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));
}
Also used : Player(example.Player) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) PlayerStats(example.PlayerStats) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) Test(org.junit.jupiter.api.Test)

Example 2 with Namespace

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));
}
Also used : NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) Table(com.yahoo.elide.modelconfig.model.Table) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TableType(com.yahoo.elide.datastores.aggregation.dynamic.TableType) Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) ImmutablePagination(com.yahoo.elide.datastores.aggregation.query.ImmutablePagination) NamespacePackage(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with Namespace

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));
}
Also used : PlayerStatsWithRequiredFilter(example.PlayerStatsWithRequiredFilter) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with Namespace

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));
}
Also used : PlayerStatsWithRequiredFilter(example.PlayerStatsWithRequiredFilter) NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 5 with Namespace

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);
}
Also used : HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Arrays(java.util.Arrays) Path(com.yahoo.elide.core.Path) Getter(lombok.Getter) IS_FIELD_HIDDEN(com.yahoo.elide.datastores.aggregation.AggregationDataStore.IS_FIELD_HIDDEN) Include(com.yahoo.elide.annotation.Include) Dimension(com.yahoo.elide.datastores.aggregation.metadata.models.Dimension) HashMap(java.util.HashMap) Function(java.util.function.Function) HashSet(java.util.HashSet) DuplicateMappingException(com.yahoo.elide.core.exceptions.DuplicateMappingException) NamespacePackage(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage) Pair(org.apache.commons.lang3.tuple.Pair) DEFAULT_NAMESPACE(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT_NAMESPACE) TableType(com.yahoo.elide.datastores.aggregation.dynamic.TableType) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) Map(java.util.Map) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) InternalServerErrorException(com.yahoo.elide.core.exceptions.InternalServerErrorException) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) Entity(javax.persistence.Entity) ApiVersion(com.yahoo.elide.annotation.ApiVersion) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) TableSource(com.yahoo.elide.datastores.aggregation.metadata.models.TableSource) DEFAULT(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) Collection(java.util.Collection) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) TimeDimensionGrain(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimensionGrain) Set(java.util.Set) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Subselect(org.hibernate.annotations.Subselect) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) List(java.util.List) Versioned(com.yahoo.elide.datastores.aggregation.metadata.models.Versioned) TypeHelper.getClassType(com.yahoo.elide.core.utils.TypeHelper.getClassType) DataStore(com.yahoo.elide.core.datastore.DataStore) Type(com.yahoo.elide.core.type.Type) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Annotation(java.lang.annotation.Annotation) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) EMPTY(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.EMPTY) MetricFormula(com.yahoo.elide.datastores.aggregation.annotation.MetricFormula) Metric(com.yahoo.elide.datastores.aggregation.metadata.models.Metric) Include(com.yahoo.elide.annotation.Include)

Aggregations

Namespace (com.yahoo.elide.datastores.aggregation.metadata.models.Namespace)9 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)7 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)6 Test (org.junit.jupiter.api.Test)6 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)5 Table (com.yahoo.elide.datastores.aggregation.metadata.models.Table)4 Query (com.yahoo.elide.datastores.aggregation.query.Query)4 PlayerStatsWithRequiredFilter (example.PlayerStatsWithRequiredFilter)4 NativeQuery (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery)3 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)2 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)2 Argument (com.yahoo.elide.core.request.Argument)2 NamespacePackage (com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage)2 TableType (com.yahoo.elide.datastores.aggregation.dynamic.TableType)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ApiVersion (com.yahoo.elide.annotation.ApiVersion)1 Include (com.yahoo.elide.annotation.Include)1 Path (com.yahoo.elide.core.Path)1 DataStore (com.yahoo.elide.core.datastore.DataStore)1