use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testBulkBytePushdown.
@Test
public void testBulkBytePushdown() throws Exception {
// $NON-NLS-1$
String preparedSql = "insert into g1 (e1) values (?)";
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table g1 (e1 varbinary) options (updatable true)", "y", "z");
// Create a testable prepared plan cache
SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
// Construct data manager with data
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData("INSERT INTO g1 (e1) VALUES (?)", new List[] { Arrays.asList(1), Arrays.asList(1) });
// Source capabilities must support batched updates
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BULK_UPDATE, true);
// $NON-NLS-1$
capFinder.addCapabilities("z", caps);
ArrayList<List<?>> values = new ArrayList<List<?>>(2);
// $NON-NLS-1$
values.add(Arrays.asList(new byte[1]));
// $NON-NLS-1$
values.add(Arrays.asList(new byte[1]));
List<?>[] expected = new List[] { Arrays.asList(1), Arrays.asList(1) };
// Create the plan and process the query
TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, tm, prepPlanCache, false, false, false, tm.getVdbMetaData());
Insert insert = (Insert) dataManager.getCommandHistory().iterator().next();
Constant c = (Constant) insert.getValues().get(0);
assertTrue(c.isMultiValued());
assertTrue(((List<?>) c.getValue()).get(0) instanceof BinaryType);
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class ResultSetImpl method getObjectDirect.
/**
* Get the value of the current row at the column index specified.
* @param column Column index
* @return Value at column, which may be null
* @throws SQLException if this result set has an exception
*/
public Object getObjectDirect(int column) throws SQLException {
checkClosed();
if (column < 1 || column > columnCount) {
// $NON-NLS-1$
throw new IllegalArgumentException(JDBCPlugin.Util.getString("ResultsImpl.Invalid_col_index", column));
}
List<?> cursorRow = batchResults.getCurrentRow();
if (cursorRow == null) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("ResultsImpl.The_cursor_is_not_on_a_valid_row._1"));
}
// defect 13539 - set the currentValue (defined in MMResultSet) so that wasNull() accurately returns whether this value was null
currentValue = cursorRow.get(column - 1);
if (currentValue instanceof Streamable<?>) {
Object reference = ((Streamable<?>) currentValue).getReference();
if (reference != null) {
return reference;
}
if (currentValue instanceof ClobType) {
return new ClobImpl(createInputStreamFactory((ClobType) currentValue), ((ClobType) currentValue).getLength());
} else if (currentValue instanceof BlobType) {
InputStreamFactory isf = createInputStreamFactory((BlobType) currentValue);
isf.setLength(((BlobType) currentValue).getLength());
return new BlobImpl(isf);
} else if (currentValue instanceof XMLType) {
XMLType val = (XMLType) currentValue;
SQLXMLImpl impl = new SQLXMLImpl(createInputStreamFactory(val));
impl.setEncoding(val.getEncoding());
return impl;
}
} else if (currentValue instanceof java.util.Date) {
return TimestampWithTimezone.create((java.util.Date) currentValue, serverTimeZone, getDefaultCalendar(), currentValue.getClass());
} else if (maxFieldSize > 0 && currentValue instanceof String) {
String val = (String) currentValue;
return val.substring(0, Math.min(maxFieldSize / 2, val.length()));
} else if (currentValue instanceof BinaryType) {
BinaryType val = (BinaryType) currentValue;
return val.getBytesDirect();
}
return currentValue;
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class CassandraUpdateExecution method internalExecute.
private void internalExecute() throws TranslatorException {
if (this.command instanceof BatchedUpdates) {
handleBatchedUpdates();
return;
}
CassandraSQLVisitor visitor = new CassandraSQLVisitor();
visitor.translateSQL(this.command);
String cql = visitor.getTranslatedSQL();
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Source-Query:", cql);
this.executionContext.logCommand(cql);
if (this.command instanceof BulkCommand) {
BulkCommand bc = (BulkCommand) this.command;
if (bc.getParameterValues() != null) {
int count = 0;
List<Object[]> newValues = new ArrayList<Object[]>();
Iterator<? extends List<?>> values = bc.getParameterValues();
while (values.hasNext()) {
Object[] bindValues = values.next().toArray();
for (int i = 0; i < bindValues.length; i++) {
if (bindValues[i] instanceof Blob) {
Blob blob = (Blob) bindValues[i];
try {
if (blob.length() > Integer.MAX_VALUE) {
// $NON-NLS-1$
throw new AssertionError("Blob is too large");
}
byte[] bytes = ((Blob) bindValues[i]).getBytes(0, (int) blob.length());
bindValues[i] = ByteBuffer.wrap(bytes);
} catch (SQLException e) {
throw new TranslatorException(e);
}
} else if (bindValues[i] instanceof BinaryType) {
bindValues[i] = ByteBuffer.wrap(((BinaryType) bindValues[i]).getBytesDirect());
}
}
newValues.add(bindValues);
count++;
}
updateCount = count;
resultSetFuture = connection.executeBatch(cql, newValues);
return;
}
}
resultSetFuture = connection.executeQuery(cql);
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class TestGeometry method testRoundTrip.
@Test
public void testRoundTrip() throws Exception {
Expression ex = TestFunctionResolving.getExpression("ST_GeomFromText('POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))')");
GeometryType geom = (GeometryType) Evaluator.evaluate(ex);
assertEquals(0, geom.getSrid());
byte[] bytes = geom.getBytes(1, (int) geom.length());
Expression ex1 = TestFunctionResolving.getExpression("ST_GeomFromBinary(X'" + new BinaryType(bytes) + "', 8307)");
GeometryType geom1 = (GeometryType) Evaluator.evaluate(ex1);
assertEquals(8307, geom1.getSrid());
assertEquals(geom, geom1);
}
use of org.teiid.core.types.BinaryType in project teiid by teiid.
the class TestGeometry method testEwkbZCooridinate.
@Test(expected = ExpressionEvaluationException.class)
public void testEwkbZCooridinate() throws Exception {
WKBWriter writer = new WKBWriter(3, true);
GeometryFactory gf = new GeometryFactory();
Point point = gf.createPoint(new Coordinate(0, 0, 0));
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);
}
Aggregations