Search in sources :

Example 66 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class DQPWorkContext method getAllowedDataPolicies.

public HashMap<String, DataPolicy> getAllowedDataPolicies() {
    if (this.policies == null) {
        this.policies = new HashMap<String, DataPolicy>();
        Set<String> userRoles = getUserRoles();
        // get data roles from the VDB
        VDBMetaData vdb = getVDB();
        TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
        Collection<? extends DataPolicy> allPolicies = null;
        if (metadata == null) {
            allPolicies = vdb.getDataPolicies();
        } else {
            allPolicies = metadata.getPolicies().values();
        }
        for (DataPolicy policy : allPolicies) {
            if (matchesPrincipal(userRoles, policy)) {
                this.policies.put(policy.getName(), policy);
            }
        }
    }
    return this.policies;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) DataPolicy(org.teiid.adminapi.DataPolicy)

Example 67 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcessor method testLateralJoinMixedFromClause.

@Test
public void testLateralJoinMixedFromClause() throws Exception {
    String ddl = "create view v as select 1 a, 2 b;";
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "x", "views");
    String sql = "select x4.*,x3.*,x2.*,x1.* from v x1, table(select x1.a a) x2 join v x3 on x2.a=x3.a join v x4 on x4.a=x3.a";
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(caps));
    HardcodedDataManager dataManager = new HardcodedDataManager();
    TestProcessor.helpProcess(plan, dataManager, new List<?>[] { Arrays.asList(1, 2, 1, 2, 1, 1, 2) });
    sql = "select x4.*,x3.*,x2.*,x1.* from views.v x1, xmltable('/a' PASSING xmlparse(document '<a id=\"' || x1.a || '\"/>') COLUMNS a integer PATH '@id') x2 join views.v x3 on x2.a=x3.a join views.v x4 on x4.a=x3.a";
    plan = TestProcessor.helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(caps));
    TestProcessor.helpProcess(plan, dataManager, new List<?>[] { Arrays.asList(1, 2, 1, 2, 1, 1, 2) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 68 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcessor method testOuterJoinWithNoOuterSources.

@Test
public void testOuterJoinWithNoOuterSources() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table test_emails(email string); CREATE view test_view_emails as SELECT 'test1@mail.com' as email", "x", "pm1");
    String sql = "SELECT a.email, b.email, lower(a.email), lower(b.email) FROM test_emails as a right outer join test_view_emails as b on lower(a.email)=lower(b.email)";
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT pm1.test_emails.email FROM pm1.test_emails", Arrays.asList("Test1@mail.com"), Arrays.asList("test2@mail.com"));
    TestProcessor.helpProcess(plan, dataManager, new List<?>[] { Arrays.asList("Test1@mail.com", "test1@mail.com", "test1@mail.com", "test1@mail.com") });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Test(org.junit.Test)

Example 69 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcessor method testMixedAnsiLateralJoinsWithConstantProjection.

@Test
public void testMixedAnsiLateralJoinsWithConstantProjection() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE VIRTUAL PROCEDURE pr0(arg1 string) returns (res1 string) AS\n" + "    BEGIN\n" + "        SELECT '2017-01-01';\n" + "    END;" + "create foreign table test_t1(col_t1 varchar) options (cardinality 1)", "x", "y");
    String sql = "SELECT d.*,x.*,xxx.*,dl.*\n" + "    FROM (SELECT 'League' AS type, 1 AS arg0) xxx, test_t1 dl, table(CALL pr0(arg0)) x\n" + "    JOIN test_t1 d ON d.col_t1 = 'str_val'";
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_LATERAL, true);
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(caps));
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.col_t1 FROM y.test_t1 AS g_0 WHERE g_0.col_t1 = 'str_val'", Arrays.asList("str_val"));
    dataManager.addData("SELECT g_0.col_t1 FROM y.test_t1 AS g_0", Arrays.asList("str_val"));
    TestProcessor.helpProcess(plan, dataManager, new List<?>[] { Arrays.asList("str_val", "2017-01-01", "League", 1, "str_val") });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 70 with TransformationMetadata

use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.

the class TestProcessor method testUpsert.

@Test
public void testUpsert() throws Exception {
    // $NON-NLS-1$
    String sql = "upsert into pm1.g1 (pm1.g1.e1, pm1.g1.e2) values ('MyString', 1)";
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table g1 (e1 string, e2 integer, primary key (e1)) options (updatable true)", "x", "pm1");
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT 1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'MyString'", new List[] { Arrays.asList(1) });
    dataManager.addData("UPDATE pm1.g1 SET e2 = 1 WHERE pm1.g1.e1 = 'MyString'", new List[] { Arrays.asList(1) });
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    ProcessorPlan plan = helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(bsc));
    helpProcess(plan, dataManager, expected);
    dataManager.clearData();
    // plan again with upsert pushdown
    dataManager.addData("UPSERT INTO pm1.g1 (e1, e2) VALUES ('MyString', 1)", Arrays.asList(1));
    bsc.setCapabilitySupport(Capability.UPSERT, true);
    plan = helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(bsc));
    helpProcess(plan, dataManager, expected);
}
Also used : BigInteger(java.math.BigInteger) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)427 Test (org.junit.Test)352 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)163 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)108 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)97 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)89 List (java.util.List)83 CommandContext (org.teiid.query.util.CommandContext)64 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)63 ArrayList (java.util.ArrayList)56 TranslationUtility (org.teiid.cdk.api.TranslationUtility)35 MetadataFactory (org.teiid.metadata.MetadataFactory)35 FakeDataManager (org.teiid.query.processor.FakeDataManager)35 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)35 Schema (org.teiid.metadata.Schema)33 Table (org.teiid.metadata.Table)27 FunctionTree (org.teiid.query.function.FunctionTree)22 Column (org.teiid.metadata.Column)21 Command (org.teiid.language.Command)20 UDFSource (org.teiid.query.function.UDFSource)20