Search in sources :

Example 21 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryExpressionJoin.

@Test
public void testSubqueryExpressionJoin() throws Exception {
    CommandContext cc = new CommandContext();
    cc.setOptions(new Options().subqueryUnnestDefault(true));
    TestQueryRewriter.helpTestRewriteCommand("Select e1 from pm3.g1 where pm3.g1.e2 < (Select max(e2) from pm2.g2 where e1 = pm3.g1.e1 having convert(min(e2), string) > pm3.g1.e1)", "SELECT e1 FROM pm3.g1, (SELECT MAX(e2) AS expr1, e1, MIN(e2) AS expr3 FROM pm2.g2 GROUP BY e1) AS X__1 WHERE (convert(X__1.expr3, string) > pm3.g1.e1) AND (pm3.g1.e2 < X__1.expr1) AND (pm3.g1.e1 = X__1.e1)", RealMetadataFactory.example4(), cc);
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 22 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestFunction method helpTestParseTimestamp.

public static void helpTestParseTimestamp(String tsStr, String format, String expected) throws FunctionExecutionException {
    Object actual = FunctionMethods.parseTimestamp(new CommandContext(), tsStr, format);
    assertEquals(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "parseTimestamp(" + tsStr + ", " + format + ") failed", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    expected.toString(), new Constant(actual).toString());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) Constant(org.teiid.query.sql.symbol.Constant)

Example 23 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestFunctionLibrary method helpInvokeMethod.

private Object helpInvokeMethod(String fname, Class<?>[] types, Object[] inputs, CommandContext context) throws FunctionExecutionException, BlockedException {
    if (types == null) {
        // Build type signature
        types = new Class<?>[inputs.length];
        for (int i = 0; i < inputs.length; i++) {
            types[i] = DataTypeManager.determineDataTypeClass(inputs[i]);
        }
    }
    if (context == null) {
        context = new CommandContext();
    }
    Object actualOutput = null;
    // Find function descriptor
    FunctionDescriptor descriptor = library.findFunction(fname, types);
    if (descriptor.requiresContext()) {
        // Invoke function with inputs
        Object[] in = new Object[inputs.length + 1];
        in[0] = context;
        for (int i = 0; i < inputs.length; i++) {
            in[i + 1] = inputs[i];
        }
        actualOutput = descriptor.invokeFunction(in, null, null);
    } else {
        // Invoke function with inputs
        actualOutput = descriptor.invokeFunction(inputs, null, null);
    }
    return actualOutput;
}
Also used : CommandContext(org.teiid.query.util.CommandContext)

Example 24 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestFunctionLibrary method testClobConcat.

@Test
public void testClobConcat() throws Exception {
    CommandContext c = new CommandContext();
    c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
    ClobType result = (ClobType) helpInvokeMethod("concat", new Class<?>[] { DataTypeManager.DefaultDataClasses.CLOB, DataTypeManager.DefaultDataClasses.CLOB }, new Object[] { DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.CLOB), DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.CLOB) }, c);
    String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\">" + "<Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs><?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", xml);
}
Also used : ClobType(org.teiid.core.types.ClobType) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 25 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestFunctionLibrary method testSessionVariables.

@Test
public void testSessionVariables() throws Exception {
    CommandContext c = new CommandContext();
    c.setSession(new SessionMetadata());
    Object result = helpInvokeMethod("teiid_session_set", new Class<?>[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT }, new Object[] { "key", "value" }, c);
    assertNull(result);
    result = helpInvokeMethod("teiid_session_get", new Class<?>[] { DataTypeManager.DefaultDataClasses.STRING }, new Object[] { "key" }, c);
    assertEquals("value", result);
    result = helpInvokeMethod("teiid_session_set", new Class<?>[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT }, new Object[] { "key", "value1" }, c);
    assertEquals("value", result);
    result = helpInvokeMethod("teiid_session_get", new Class<?>[] { DataTypeManager.DefaultDataClasses.STRING }, new Object[] { "key" }, c);
    assertEquals("value1", result);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) Test(org.junit.Test)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11