use of io.crate.types.DataType in project crate by crate.
the class SQLTransportExecutor method executeAndConvertResult.
private static SQLResponse executeAndConvertResult(PreparedStatement preparedStatement) throws SQLException {
if (preparedStatement.execute()) {
ResultSetMetaData metadata = preparedStatement.getMetaData();
ResultSet resultSet = preparedStatement.getResultSet();
List<Object[]> rows = new ArrayList<>();
List<String> columnNames = new ArrayList<>(metadata.getColumnCount());
DataType[] dataTypes = new DataType[metadata.getColumnCount()];
for (int i = 0; i < metadata.getColumnCount(); i++) {
columnNames.add(metadata.getColumnName(i + 1));
}
while (resultSet.next()) {
Object[] row = new Object[metadata.getColumnCount()];
for (int i = 0; i < row.length; i++) {
Object value;
String typeName = metadata.getColumnTypeName(i + 1);
value = getObject(resultSet, i, typeName);
row[i] = value;
}
rows.add(row);
}
return new SQLResponse(columnNames.toArray(new String[0]), rows.toArray(new Object[0][]), dataTypes, rows.size());
} else {
int updateCount = preparedStatement.getUpdateCount();
if (updateCount < 0) {
/*
* In Crate -1 means row-count unknown, and -2 means error. In JDBC -2 means row-count unknown and -3 means error.
* See {@link java.sql.Statement#EXECUTE_FAILED}
*/
updateCount += 1;
}
return new SQLResponse(new String[0], new Object[0][], new DataType[0], updateCount);
}
}
use of io.crate.types.DataType in project crate by crate.
the class SymbolMatchers method isFunction.
public static Matcher<Symbol> isFunction(final String name, @Nullable final List<DataType> argumentTypes) {
if (argumentTypes == null) {
return isFunction(name);
}
Matcher[] argMatchers = new Matcher[argumentTypes.size()];
ListIterator<DataType> it = argumentTypes.listIterator();
while (it.hasNext()) {
int i = it.nextIndex();
DataType type = it.next();
argMatchers[i] = hasDataType(type);
}
// noinspection unchecked
return isFunction(name, argMatchers);
}
use of io.crate.types.DataType in project crate by crate.
the class DataTypeTest method testForValueWithArrayWithNullValues.
@Test
public void testForValueWithArrayWithNullValues() {
DataType dataType = DataTypes.guessType(new String[] { "foo", null, "bar" });
assertEquals(dataType, new ArrayType(DataTypes.STRING));
}
use of io.crate.types.DataType in project crate by crate.
the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParamLiteral.
@Test
public void testUpdateDynamicNestedArrayParamLiteral() throws Exception {
AnalyzedUpdateStatement update = analyze("update users set new=[[1.9, 4.8], [9.7, 12.7]]");
DataType dataType = update.assignmentByTargetCol().values().iterator().next().valueType();
assertThat(dataType, is(new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
use of io.crate.types.DataType in project crate by crate.
the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParam.
@Test
public void testUpdateDynamicNestedArrayParam() throws Exception {
Object[] params = { new Object[] { new Object[] { 1.9, 4.8 }, new Object[] { 9.7, 12.7 } } };
AnalyzedUpdateStatement update = analyze("update users set new=? where id=1");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
DataType dataType = sources[0].valueType();
assertThat(dataType, is(new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
Aggregations