Search in sources :

Example 31 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionTree method testMultiPartName.

@Test
public void testMultiPartName() throws Exception {
    FunctionMethod method = new FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "x.y.dummy", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    PushDown.CANNOT_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    TestFunctionTree.class.getName(), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "toString", // $NON-NLS-1$
    Arrays.asList(new FunctionParameter("in", DataTypeManager.DefaultDataTypes.VARBINARY)), // $NON-NLS-1$
    new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), true, Determinism.DETERMINISTIC);
    FunctionTree sys = RealMetadataFactory.SFM.getSystemFunctions();
    FunctionLibrary fl = new FunctionLibrary(sys, new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
    assertNotNull(fl.findFunction("dummy", new Class<?>[] { DataTypeManager.DefaultDataClasses.VARBINARY }));
    assertNotNull(fl.findFunction("y.dummy", new Class<?>[] { DataTypeManager.DefaultDataClasses.VARBINARY }));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 32 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionTree method testNullCategory.

@Test
public void testNullCategory() {
    FunctionMethod method = new FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "dummy", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    PushDown.MUST_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "nonexistentClass", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "noMethod", new ArrayList<FunctionParameter>(0), // $NON-NLS-1$
    new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), false, Determinism.DETERMINISTIC);
    Collection<org.teiid.metadata.FunctionMethod> list = Arrays.asList(method);
    FunctionMetadataSource fms = Mockito.mock(FunctionMetadataSource.class);
    Mockito.stub(fms.getFunctionMethods()).toReturn(list);
    FunctionTree ft = new FunctionTree("foo", fms);
    assertEquals(1, ft.getFunctionsInCategory(FunctionCategoryConstants.MISCELLANEOUS).size());
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 33 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionMethod method testEquivalence1.

@Test
public void testEquivalence1() {
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter p1 = new FunctionParameter("in", "string");
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter pout = new FunctionParameter("out", "string");
    FunctionMethod m1 = new // $NON-NLS-1$ //$NON-NLS-2$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
    "length", // $NON-NLS-1$ //$NON-NLS-2$
    "", // $NON-NLS-1$ //$NON-NLS-2$
    FunctionCategoryConstants.STRING, // $NON-NLS-1$ //$NON-NLS-2$
    "com.metamatrix.query.function.FunctionMethods", // $NON-NLS-1$ //$NON-NLS-2$
    "length", new FunctionParameter[] { p1 }, pout);
    UnitTestUtil.helpTestEquivalence(0, m1, m1);
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 34 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestFunctionMethod method testEquivalence11.

@Test
public void testEquivalence11() {
    // $NON-NLS-1$ //$NON-NLS-2$
    FunctionParameter pout = new FunctionParameter("out", "string");
    FunctionMethod m1 = new // $NON-NLS-1$ //$NON-NLS-2$
    FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
    "length", // $NON-NLS-1$ //$NON-NLS-2$
    "", // $NON-NLS-1$ //$NON-NLS-2$
    FunctionCategoryConstants.STRING, // $NON-NLS-1$ //$NON-NLS-2$
    "com.metamatrix.query.function.FunctionMethods", // $NON-NLS-1$ //$NON-NLS-2$
    "length", null, pout);
    UnitTestUtil.helpTestEquivalence(0, m1, m1);
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 35 with FunctionParameter

use of org.teiid.metadata.FunctionParameter in project teiid by teiid.

the class TestLocalConnections method oneTimeSetup.

@SuppressWarnings("serial")
@BeforeClass
public static void oneTimeSetup() throws Exception {
    server.setUseCallingThread(true);
    server.setConnectorManagerRepository(new ConnectorManagerRepository() {

        @Override
        public ConnectorManager getConnectorManager(String connectorName) {
            return new ConnectorManager(connectorName, connectorName) {

                @Override
                public ExecutionFactory<Object, Object> getExecutionFactory() {
                    return new ExecutionFactory<Object, Object>() {

                        @Override
                        public boolean isSourceRequired() {
                            return false;
                        }

                        @Override
                        public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
                            return new ResultSetExecution() {

                                boolean returnedRow = false;

                                @Override
                                public void execute() throws TranslatorException {
                                    lock.lock();
                                    try {
                                        sourceCounter.release();
                                        if (!wait.await(5, TimeUnit.SECONDS)) {
                                            throw new RuntimeException();
                                        }
                                    } catch (InterruptedException e) {
                                        throw new RuntimeException(e);
                                    } finally {
                                        lock.unlock();
                                    }
                                }

                                @Override
                                public void close() {
                                }

                                @Override
                                public void cancel() throws TranslatorException {
                                }

                                @Override
                                public List<?> next() throws TranslatorException, DataNotAvailableException {
                                    if (returnedRow) {
                                        return null;
                                    }
                                    returnedRow = true;
                                    return new ArrayList<Object>(Collections.singleton(null));
                                }
                            };
                        }
                    };
                }

                @Override
                public Object getConnectionFactory() throws TranslatorException {
                    return null;
                }
            };
        }
    });
    FunctionMethod function = new FunctionMethod("foo", null, FunctionCategoryConstants.MISCELLANEOUS, PushDown.CANNOT_PUSHDOWN, TestLocalConnections.class.getName(), "blocking", null, new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER), false, FunctionMethod.Determinism.NONDETERMINISTIC);
    HashMap<String, Collection<FunctionMethod>> udfs = new HashMap<String, Collection<FunctionMethod>>();
    udfs.put("test", Arrays.asList(function));
    server.deployVDB("PartsSupplier", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb", new DeployVDBParameter(udfs, null));
}
Also used : HashMap(java.util.HashMap) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Execution(org.teiid.translator.Execution) ResultSetExecution(org.teiid.translator.ResultSetExecution) FunctionMethod(org.teiid.metadata.FunctionMethod) List(java.util.List) ArrayList(java.util.ArrayList) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) FunctionParameter(org.teiid.metadata.FunctionParameter) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ExecutionFactory(org.teiid.translator.ExecutionFactory) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) DeployVDBParameter(org.teiid.jdbc.FakeServer.DeployVDBParameter) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) Collection(java.util.Collection) TranslatorException(org.teiid.translator.TranslatorException) BeforeClass(org.junit.BeforeClass)

Aggregations

FunctionParameter (org.teiid.metadata.FunctionParameter)36 FunctionMethod (org.teiid.metadata.FunctionMethod)31 Test (org.junit.Test)9 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)3 ArrayList (java.util.ArrayList)2 AggregateAttributes (org.teiid.metadata.AggregateAttributes)2 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 UserDefinedAggregate (org.teiid.UserDefinedAggregate)1 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1 FunctionMetadataException (org.teiid.api.exception.query.FunctionMetadataException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 BinaryType (org.teiid.core.types.BinaryType)1 ReflectionHelper (org.teiid.core.util.ReflectionHelper)1