use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class TestGeometry method testEwkb.
@Test(expected = ExpressionEvaluationException.class)
public void testEwkb() throws Exception {
WKBWriter writer = new WKBWriter(3, true);
GeometryFactory gf = new GeometryFactory();
Point point = gf.createPoint(new Coordinate(0, 0, 0));
point.setSRID(100);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.write(point, new OutputStreamOutStream(baos));
Expression ex1 = TestFunctionResolving.getExpression("ST_GeomFromBinary(X'" + new BinaryType(baos.toByteArray()) + "', 8307)");
Evaluator.evaluate(ex1);
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class TestAggregateProcessing method testStringAggBinary.
@Test
public void testStringAggBinary() throws Exception {
// Create query
// $NON-NLS-1$
String sql = "SELECT cast(string_agg(to_bytes(e1, 'UTF-8'), X'AB') as varbinary) from pm1.g1 group by e3";
// Create expected results
List[] expected = new List[] { Arrays.asList(new BinaryType(new byte[] { (byte) 0x61, (byte) 0xAB, (byte) 0x62, (byte) 0xAB, (byte) 0x61 })), Arrays.asList(new BinaryType(new byte[] { (byte) 0x61, (byte) 0xAB, (byte) 0x63 })) };
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached(), TestAggregatePushdown.getAggregatesFinder());
helpProcess(plan, dataManager, expected);
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class DataTypeTransformer method transform.
static final <T> T transform(Object value, Class<T> targetType, Class<?> runtimeType) throws SQLException {
if (value == null || targetType.isAssignableFrom(value.getClass())) {
return targetType.cast(value);
}
if (targetType == byte[].class) {
if (value instanceof Blob) {
Blob blob = (Blob) value;
long length = blob.length();
if (length > Integer.MAX_VALUE) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("DataTypeTransformer.blob_too_big"));
}
return targetType.cast(blob.getBytes(1, (int) length));
} else if (value instanceof String) {
return targetType.cast(((String) value).getBytes());
} else if (value instanceof BinaryType) {
return targetType.cast(((BinaryType) value).getBytesDirect());
}
} else if (targetType == String.class) {
if (value instanceof SQLXML) {
return targetType.cast(((SQLXML) value).getString());
} else if (value instanceof Clob) {
Clob c = (Clob) value;
long length = c.length();
if (length == 0) {
// $NON-NLS-1$
return targetType.cast("");
}
return targetType.cast(c.getSubString(1, length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) length));
}
}
try {
return (T) DataTypeManager.transformValue(DataTypeManager.convertToRuntimeType(value, true), runtimeType);
} catch (Exception e) {
String valueStr = value.toString();
if (valueStr.length() > 20) {
// $NON-NLS-1$
valueStr = valueStr.substring(0, 20) + "...";
}
// $NON-NLS-1$
String msg = JDBCPlugin.Util.getString("DataTypeTransformer.Err_converting", valueStr, targetType.getSimpleName());
throw TeiidSQLException.create(e, msg);
}
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class XQueryEvaluator method evaluateXQuery.
public static SaxonXQueryExpression.Result evaluateXQuery(final SaxonXQueryExpression xquery, Object context, Map<String, Object> parameterValues, final RowProcessor processor, CommandContext commandContext) throws TeiidProcessingException, TeiidComponentException {
DynamicQueryContext dynamicContext = new DynamicQueryContext(xquery.config);
SaxonXQueryExpression.Result result = new SaxonXQueryExpression.Result();
try {
for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
try {
Object value = entry.getValue();
Sequence s = null;
if (value instanceof SQLXML) {
value = XMLSystemFunctions.convertToSource(value);
result.sources.add((Source) value);
Source source = wrapStax((Source) value);
s = xquery.config.buildDocumentTree(source).getRootNode();
} else if (value instanceof java.util.Date) {
s = XQueryEvaluator.convertToAtomicValue(value);
} else if (value instanceof BinaryType) {
s = new HexBinaryValue(((BinaryType) value).getBytesDirect());
}
dynamicContext.setParameter(StructuredQName.fromClarkName(entry.getKey()), s);
} catch (TransformerException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30148, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30148, entry.getKey()));
}
}
if (context != null) {
Source source = XMLSystemFunctions.convertToSource(context);
result.sources.add(source);
source = wrapStax(source);
if (xquery.contextRoot != null) {
// create our own filter as this logic is not provided in the free saxon
AugmentedSource sourceInput = AugmentedSource.makeAugmentedSource(source);
sourceInput.addFilter(new FilterFactory() {
@Override
public ProxyReceiver makeFilter(Receiver arg0) {
return new PathMapFilter(xquery.contextRoot, arg0);
}
});
source = sourceInput;
// use streamable processing instead
if (xquery.streamingPath != null && processor != null) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, "Using stream processing for evaluation of", xquery.xQueryString);
}
// set to non-blocking in case default expression evaluation blocks
boolean isNonBlocking = commandContext.isNonBlocking();
commandContext.setNonBlocking(true);
final StreamingTransform myTransform = new StreamingTransform() {
public Nodes transform(Element elem) {
processor.processRow(XQueryEvaluator.wrap(elem, xquery.config));
return NONE;
}
};
Builder builder = new Builder(new SaxonReader(xquery.config, sourceInput), false, new StreamingPathFilter(xquery.streamingPath, xquery.namespaceMap).createNodeFactory(null, myTransform));
try {
// the builder is hard wired to parse the source, but the api will throw an exception if the stream is null
builder.build(FAKE_IS);
return result;
} catch (ParsingException e) {
if (e.getCause() instanceof TeiidRuntimeException) {
RelationalNode.unwrapException((TeiidRuntimeException) e.getCause());
}
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
} finally {
if (!isNonBlocking) {
commandContext.setNonBlocking(false);
}
}
}
}
TreeInfo doc;
try {
doc = xquery.config.buildDocumentTree(source);
} catch (XPathException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30151, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30151));
}
dynamicContext.setContextItem(doc.getRootNode());
}
try {
result.iter = xquery.xQuery.iterator(dynamicContext);
return result;
} catch (TransformerException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30152, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30152));
}
} finally {
if (result.iter == null) {
result.close();
}
}
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class TestSizeUtility method testGetSizeByteArray.
@Test
public void testGetSizeByteArray() {
byte[] bytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
helpTestGetSize(new BinaryType(bytes), 32);
}
Aggregations