Search in sources :

Example 1 with NamespaceConfig

use of com.yahoo.elide.modelconfig.model.NamespaceConfig 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 2 with NamespaceConfig

use of com.yahoo.elide.modelconfig.model.NamespaceConfig in project elide by yahoo.

the class NamespacePackageTest method testAnnotations.

@Test
void testAnnotations() throws Exception {
    NamespaceConfig testNamespace = NamespaceConfig.builder().description("A test Namespace").name("Test").build();
    NamespacePackage namespace = new NamespacePackage(testNamespace);
    ReadPermission readPermission = namespace.getDeclaredAnnotation(ReadPermission.class);
    assertEquals("Prefab.Role.All", readPermission.expression());
    Include meta = namespace.getDeclaredAnnotation(Include.class);
    assertEquals("A test Namespace", meta.description());
    assertNull(meta.friendlyName());
    ApiVersion apiVersion = namespace.getDeclaredAnnotation(ApiVersion.class);
    assertEquals("", apiVersion.version());
}
Also used : NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) ApiVersion(com.yahoo.elide.annotation.ApiVersion) Include(com.yahoo.elide.annotation.Include) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Test(org.junit.jupiter.api.Test)

Example 3 with NamespaceConfig

use of com.yahoo.elide.modelconfig.model.NamespaceConfig in project elide by yahoo.

the class DynamicConfigValidator method validateNamespaceConfig.

/**
 * Validate namespace configs.
 * @return boolean true if all provided namespace properties passes validation
 */
private boolean validateNamespaceConfig() {
    Set<String> extractedChecks = new HashSet<>();
    PermissionExpressionVisitor visitor = new PermissionExpressionVisitor();
    for (NamespaceConfig namespace : elideNamespaceConfig.getNamespaceconfigs()) {
        extractChecksFromExpr(namespace.getReadAccess(), extractedChecks, visitor);
    }
    validateChecks(extractedChecks, Collections.EMPTY_SET);
    return true;
}
Also used : NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) ElideNamespaceConfig(com.yahoo.elide.modelconfig.model.ElideNamespaceConfig) HashSet(java.util.HashSet)

Example 4 with NamespaceConfig

use of com.yahoo.elide.modelconfig.model.NamespaceConfig in project elide by yahoo.

the class NamespacePackageTest method testGet.

@Test
void testGet() throws Exception {
    NamespaceConfig testNamespace = NamespaceConfig.builder().description("A test Namespace").name("Test").build();
    NamespacePackage namespace = new NamespacePackage(testNamespace);
    assertEquals("Test", namespace.getName());
}
Also used : NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) Test(org.junit.jupiter.api.Test)

Aggregations

NamespaceConfig (com.yahoo.elide.modelconfig.model.NamespaceConfig)4 Test (org.junit.jupiter.api.Test)3 ApiVersion (com.yahoo.elide.annotation.ApiVersion)1 Include (com.yahoo.elide.annotation.Include)1 ReadPermission (com.yahoo.elide.annotation.ReadPermission)1 NamespacePackage (com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage)1 TableType (com.yahoo.elide.datastores.aggregation.dynamic.TableType)1 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)1 Namespace (com.yahoo.elide.datastores.aggregation.metadata.models.Namespace)1 ImmutablePagination (com.yahoo.elide.datastores.aggregation.query.ImmutablePagination)1 Query (com.yahoo.elide.datastores.aggregation.query.Query)1 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)1 ElideNamespaceConfig (com.yahoo.elide.modelconfig.model.ElideNamespaceConfig)1 Table (com.yahoo.elide.modelconfig.model.Table)1 HashSet (java.util.HashSet)1