@Test
  public void testDDLMetadata1() throws Exception {
    String ddl =
        "CREATE foreign FUNCTION sourceFunc(msg varchar) RETURNS varchar options (nameinsource 'a.sourcefunc') "
            + "CREATE foreign FUNCTION b.sourceFunc(msg varchar) RETURNS varchar "
            + "CREATE foreign table X (Y varchar);";

    QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy");

    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    capFinder.addCapabilities("phy", caps); // $NON-NLS-1$

    ProcessorPlan plan =
        helpPlan(
            "SELECT sourceFunc(g_0.Y), phy.b.sourceFunc(g_0.Y) FROM phy.X AS g_0",
            metadata,
            null,
            capFinder,
            new String[] {"SELECT sourceFunc(g_0.Y), phy.b.sourceFunc(g_0.Y) FROM phy.X AS g_0"},
            ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$

    // ensure that the source query contains the function schemas
    HardcodedDataManager dm = new HardcodedDataManager(metadata);
    dm.addData("SELECT a.sourcefunc(g_0.Y), b.sourceFunc(g_0.Y) FROM X AS g_0", new List[0]);
    TestProcessor.helpProcess(plan, dm, new List[0]);
  }
Beispiel #2
0
  private ArrayList helpExecute(String ddl, FileConnection connection, String query)
      throws Exception {
    ExcelExecutionFactory translator = new ExcelExecutionFactory();
    translator.start();

    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "vdb", "excel");
    TranslationUtility utility = new TranslationUtility(metadata);

    Command cmd = utility.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);

    ResultSetExecution execution =
        translator.createResultSetExecution(
            (QueryExpression) cmd, context, utility.createRuntimeMetadata(), connection);
    execution.execute();

    ArrayList results = new ArrayList();
    while (true) {
      List<?> row = execution.next();
      if (row == null) {
        break;
      }
      results.add(row);
    }
    return results;
  }
  @Test
  public void testProjectedColumns() throws Exception {
    TransformationMetadata metadata =
        RealMetadataFactory.fromDDL(
            ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")),
            "northwind",
            "nw");
    EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
    Client client = mock(Client.class);
    stub(client.getMetadataStore()).toReturn(metadata.getMetadataStore());
    stub(client.getMetadata()).toReturn(eds);
    MockProvider.CLIENT = client;
    ArgumentCaptor<String> sql = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<EdmEntitySet> entitySet = ArgumentCaptor.forClass(EdmEntitySet.class);

    OEntity entity = createCustomersEntity(eds);
    List<OEntity> result = new ArrayList<OEntity>();
    result.add(entity);

    when(client.sqlExecute(
            anyString(),
            anyListOf(SQLParam.class),
            any(EdmEntitySet.class),
            anyMapOf(String.class, Boolean.class)))
        .thenReturn(result);

    ClientRequest request =
        new ClientRequest(
            TestPortProvider.generateURL(
                "/odata/northwind/Customers?$select=CustomerID,CompanyName,Address"));
    ClientResponse<String> response = request.get(String.class);
    verify(client)
        .sqlExecute(
            sql.capture(),
            anyListOf(SQLParam.class),
            entitySet.capture(),
            anyMapOf(String.class, Boolean.class));

    Assert.assertEquals(
        "SELECT g0.Address, g0.CustomerID, g0.CompanyName FROM Customers AS g0", sql.getValue());
    Assert.assertEquals(200, response.getStatus());
    // Assert.assertEquals("", response.getEntity());
  }
  @Test
  public void testDDLMetadataNameConflict() throws Exception {
    String ddl =
        "CREATE foreign FUNCTION \"convert\"(msg integer, type varchar) RETURNS varchar "
            + "CREATE foreign table X (Y integer);";

    QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy");

    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    capFinder.addCapabilities("phy", caps); // $NON-NLS-1$

    helpPlan(
        "select phy.convert(y, 'z') from x",
        metadata,
        null,
        capFinder,
        new String[] {"SELECT phy.convert(g_0.Y, 'z') FROM phy.X AS g_0"},
        ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$
  }
Beispiel #5
0
  @Test
  public void testInherentUpdateUsingTemp() throws Exception {
    TransformationMetadata metadata =
        RealMetadataFactory.fromDDL(
            "create foreign table g1 (e1 string primary key, e2 integer, e3 boolean, e4 double, FOREIGN KEY (e1) REFERENCES G2 (e1)) options (updatable true);"
                + " create foreign table g2 (e1 string primary key, e2 integer, e3 boolean, e4 double) options (updatable true);"
                + " create view v options (updatable true) as select g1.e2 from g1 inner join g2 on g1.e1 = g2.e1;",
            "x",
            "pm1");
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    setUp(metadata, hdm);

    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    SessionAwareCache<CachedResults> cache =
        new SessionAwareCache<CachedResults>(
            "resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    cache.setTupleBufferCache(bm);
    dataManager = new TempTableDataManager(hdm, bm, cache);

    execute(
        "create temporary table x (e1 string, e2 integer, e3 string, primary key (e1))",
        new List[] {Arrays.asList(0)}); // $NON-NLS-1$

    execute("insert into x values ('a', 1, 'b')", new List[] {Arrays.asList(1)});

    TempMetadataID id = this.tempStore.getMetadataStore().getData().get("x");

    // ensure that we're using the actual metadata
    assertNotNull(id);
    assertNotNull(this.metadata.getPrimaryKey(id));

    hdm.addData(
        "SELECT g_0.e1 FROM g1 AS g_0, g2 AS g_1 WHERE g_0.e1 = g_1.e1 AND g_0.e2 = 1",
        new List[] {Arrays.asList("a")});
    hdm.addData("DELETE FROM g1 WHERE g1.e1 = 'a'", new List[] {Arrays.asList(1)});

    execute(
        "delete from v where e2 = (select max(e2) from x as z where e3 = z.e3)",
        new List[] {Arrays.asList(1)},
        TestOptimizer.getGenericFinder()); // $NON-NLS-1$
  }
  @Test
  public void testMetadata() throws Exception {
    TransformationMetadata metadata =
        RealMetadataFactory.fromDDL(
            ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")),
            "northwind",
            "nw");
    EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
    Client client = mock(Client.class);
    stub(client.getMetadataStore()).toReturn(metadata.getMetadataStore());
    stub(client.getMetadata()).toReturn(eds);
    MockProvider.CLIENT = client;

    StringWriter sw = new StringWriter();

    EdmxFormatWriter.write(eds, sw);

    ClientRequest request =
        new ClientRequest(TestPortProvider.generateURL("/odata/northwind/$metadata"));
    ClientResponse<String> response = request.get(String.class);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(sw.toString(), response.getEntity());
  }
 public static QueryMetadataInterface exampleLdap() throws Exception {
   String ddl =
       "create foreign table People (UserID string options (nameinsource 'uid'), Name string options (nameinsource 'cn'), dn string, vals string[]) options (nameinsource 'ou=people,dc=metamatrix,dc=com');"
           + "create foreign table People_Groups (user_dn string options (nameinsource 'dn'), groupname string options (nameinsource 'memberOf', \"teiid_ldap:dn_prefix\" 'ou=groups,dc=metamatrix,dc=com', \"teiid_ldap:rdn_type\" 'cn')) options (nameinsource 'ou=people,dc=metamatrix,dc=com')";
   return RealMetadataFactory.fromDDL(ddl, "x", "LdapModel");
 }