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);
}
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());
}
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;
}
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);
}
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);
}
Aggregations