Ejemplo n.º 1
0
  @Test
  public void testMustPushdownOverMultipleSourcesWithViewDupRemoval() throws Exception {
    QueryMetadataInterface metadata =
        RealMetadataFactory.createTransformationMetadata(
            RealMetadataFactory.example1Cached().getMetadataStore(),
            "example1",
            new FunctionTree("foo", new FakeFunctionMetadataSource()));

    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setFunctionSupport("misc.namespace.func", true);
    capFinder.addCapabilities("pm1", caps); // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps); // $NON-NLS-1$

    String sql =
        "select func(x.e1) from (select distinct x.* from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2 order by e1 limit 10) as x"; //$NON-NLS-1$

    helpPlan(
        sql,
        metadata,
        null,
        capFinder,
        new String[] {},
        ComparisonMode.FAILED_PLANNING); // $NON-NLS-1$
  }
 public static TransformationMetadata getTransformationMetadata(
     MetadataFactory mf, ODataExecutionFactory ef) throws Exception {
   TransformationMetadata metadata =
       RealMetadataFactory.createTransformationMetadata(
           mf.asMetadataStore(),
           "trippin",
           new FunctionTree("foo", new UDFSource(ef.getPushDownFunctions())));
   ValidatorReport report =
       new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
   if (report.hasItems()) {
     throw new RuntimeException(report.getFailureMessage());
   }
   return metadata;
 }
Ejemplo n.º 3
0
  @Test
  public void testStreaming() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    MetadataFactory mf =
        new MetadataFactory(
            "vdb",
            1,
            "x",
            SystemMetadata.getInstance().getRuntimeTypeMap(),
            new Properties(),
            null);
    ef.getMetadata(mf, null);
    Procedure p = mf.getSchema().getProcedure(WSExecutionFactory.INVOKE_HTTP);
    assertEquals(7, p.getParameters().size());

    TransformationMetadata tm =
        RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    Dispatch<Object> mockDispatch = mockDispatch();
    DataSource mock = Mockito.mock(DataSource.class);
    ByteArrayInputStream baos = new ByteArrayInputStream(new byte[100]);
    Mockito.stub(mock.getInputStream()).toReturn(baos);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(mock);
    Mockito.stub(
            mockConnection.createDispatch(
                Mockito.any(String.class),
                Mockito.any(String.class),
                Mockito.any(Class.class),
                Mockito.any(Service.Mode.class)))
        .toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);

    Call call = (Call) cb.getCommand("call invokeHttp('GET', null, null, true)");
    BinaryWSProcedureExecution pe =
        new BinaryWSProcedureExecution(
            call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    pe.execute();
    List<?> result = pe.getOutputParameterValues();

    Blob b = (Blob) result.get(0);
    assertEquals(100, ObjectConverterUtil.convertToByteArray(b.getBinaryStream()).length);
    try {
      ObjectConverterUtil.convertToByteArray(b.getBinaryStream());
      fail();
    } catch (SQLException e) {
      // should only be able to read once
    }
  }
Ejemplo n.º 4
0
  @Test
  public void testHeaders() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    MetadataFactory mf =
        new MetadataFactory(
            "vdb",
            1,
            "x",
            SystemMetadata.getInstance().getRuntimeTypeMap(),
            new Properties(),
            null);
    ef.getMetadata(mf, null);
    Procedure p = mf.getSchema().getProcedure(WSExecutionFactory.INVOKE_HTTP);

    TransformationMetadata tm =
        RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    Dispatch<Object> mockDispatch = mockDispatch();
    DataSource mock = Mockito.mock(DataSource.class);
    ByteArrayInputStream baos = new ByteArrayInputStream(new byte[100]);
    Mockito.stub(mock.getInputStream()).toReturn(baos);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(mock);
    Mockito.stub(
            mockConnection.createDispatch(
                Mockito.any(String.class),
                Mockito.any(String.class),
                Mockito.any(Class.class),
                Mockito.any(Service.Mode.class)))
        .toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);

    Call call =
        (Call)
            cb.getCommand(
                "call invokeHttp('GET', null, null, false, '{\"ContentType\":\"application/json\"}')");
    BinaryWSProcedureExecution pe =
        new BinaryWSProcedureExecution(
            call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    pe.execute();

    Map<String, List<String>> headers =
        (Map<String, List<String>>)
            mockDispatch.getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);
    assertEquals(Arrays.asList("application/json"), headers.get("ContentType"));
  }
Ejemplo n.º 5
0
  @Test
  public void testDDLMetadata() throws Exception {
    String ddl =
        "CREATE VIRTUAL FUNCTION SourceFunc(msg varchar) RETURNS varchar "
            + "OPTIONS(CATEGORY 'misc', DETERMINISM 'DETERMINISTIC', "
            + "\"NULL-ON-NULL\" 'true', JAVA_CLASS '"
            + TestFunctionPushdown.class.getName()
            + "', JAVA_METHOD 'sourceFunc');"
            + "CREATE VIEW X (Y varchar) as SELECT e1 from pm1.g1;";

    MetadataFactory mf = TestDDLParser.helpParse(ddl, "model");
    mf.getSchema().setPhysical(false);
    MetadataStore ms = mf.asMetadataStore();
    ms.merge(RealMetadataFactory.example1Cached().getMetadataStore());

    QueryMetadataInterface metadata =
        RealMetadataFactory.createTransformationMetadata(ms, "example1");

    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setFunctionSupport("model.SourceFunc", true);
    capFinder.addCapabilities("pm1", caps); // $NON-NLS-1$

    helpPlan(
        "select sourceFunc(y) from x",
        metadata,
        null,
        capFinder,
        new String[] {"SELECT sourceFunc(g_0.e1) FROM pm1.g1 AS g_0"},
        ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$

    caps.setFunctionSupport("model.SourceFunc", false);

    helpPlan(
        "select sourceFunc(y) from x",
        metadata,
        null,
        capFinder,
        new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"},
        ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$
  }
Ejemplo n.º 6
0
  @Test
  public void testMustPushdownOverMultipleSources() throws Exception {
    QueryMetadataInterface metadata =
        RealMetadataFactory.createTransformationMetadata(
            RealMetadataFactory.example1Cached().getMetadataStore(),
            "example1",
            new FunctionTree("foo", new FakeFunctionMetadataSource()));

    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setFunctionSupport("misc.namespace.func", true);
    capFinder.addCapabilities("pm1", caps); // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps); // $NON-NLS-1$

    String sql = "select func(x.e1) from pm1.g1 as x, pm2.g1 as y where x.e2 = y.e2"; // $NON-NLS-1$

    ProcessorPlan plan =
        helpPlan(
            sql,
            metadata,
            null,
            capFinder,
            new String[] {
              "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0",
              "SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0"
            },
            ComparisonMode.EXACT_COMMAND_STRING); // $NON-NLS-1$

    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData(
        "SELECT g_0.e2 AS c_0, func(g_0.e1) AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0",
        new List[] {Arrays.asList(1, "a")});
    dataManager.addData(
        "SELECT g_0.e2 AS c_0 FROM pm2.g1 AS g_0 ORDER BY c_0",
        new List[] {Arrays.asList(1), Arrays.asList(2)});

    TestProcessor.helpProcess(plan, dataManager, new List[] {Arrays.asList("a")});
  }
Ejemplo n.º 7
0
  @Test
  public void testPre81Procedure() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    MetadataFactory mf =
        new MetadataFactory(
            "vdb",
            1,
            "x",
            SystemMetadata.getInstance().getRuntimeTypeMap(),
            new Properties(),
            null);
    ef.getMetadata(mf, null);
    Procedure p = mf.getSchema().getProcedure(WSExecutionFactory.INVOKE_HTTP);
    assertEquals(7, p.getParameters().size());
    p.getParameters().remove(4);
    p.getParameters().remove(5);
    p = mf.getSchema().getProcedure("invoke");
    assertEquals(6, p.getParameters().size());
    p.getParameters().remove(5);
    // designer treated the result as an out parameter
    p.getParameters().get(0).setType(Type.Out);
    p.getParameters().add(p.getParameters().remove(0));
    for (int i = 0; i < p.getParameters().size(); i++) {
      p.getParameters().get(i).setPosition(i + 1);
    }

    TransformationMetadata tm =
        RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    Dispatch<Object> mockDispatch = mockDispatch();
    DataSource source = Mockito.mock(DataSource.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(source);
    Mockito.stub(
            mockConnection.createDispatch(
                Mockito.any(String.class),
                Mockito.any(String.class),
                Mockito.any(Class.class),
                Mockito.any(Service.Mode.class)))
        .toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);

    Call call = (Call) cb.getCommand("call invokeHttp('GET', null, null)");
    BinaryWSProcedureExecution pe =
        new BinaryWSProcedureExecution(
            call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    pe.execute();
    pe.getOutputParameterValues();

    mockConnection = Mockito.mock(WSConnection.class);
    mockDispatch = Mockito.mock(Dispatch.class);
    StAXSource ssource = Mockito.mock(StAXSource.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(StAXSource.class))).toReturn(ssource);
    Mockito.stub(
            mockConnection.createDispatch(
                Mockito.any(String.class),
                Mockito.any(String.class),
                Mockito.any(Class.class),
                Mockito.any(Service.Mode.class)))
        .toReturn(mockDispatch);
    call = (Call) cb.getCommand("call invoke()");
    WSProcedureExecution wpe =
        new WSProcedureExecution(
            call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    wpe.execute();
    wpe.getOutputParameterValues();
  }