This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new b99e2dc727 [bug](jdbc) fix jdbc can't get object of PGobject (#16496)
b99e2dc727 is described below
commit b99e2dc7273d5e8b44cf081106656546ee4802e5
Author: zhangstar333 <[email protected]>
AuthorDate: Fri Feb 10 16:19:02 2023 +0800
[bug](jdbc) fix jdbc can't get object of PGobject (#16496)
when pg table have some unsupported column type like: point, polygon,
jsonb......
jdbc catalog will convert it to string type in doris. but get result set in
java is org.postgresql.util.PGobject
Some test need this pr: #16442
---
be/src/vec/exec/vjdbc_connector.cpp | 17 +-
be/src/vec/exec/vjdbc_connector.h | 1 +
.../java/org/apache/doris/udf/JdbcExecutor.java | 689 +++++++++++++++++----
.../suites/jdbc_p0/test_jdbc_query_mysql.groovy | 3 +-
.../suites/jdbc_p0/test_jdbc_query_pg.groovy | 3 +-
5 files changed, 590 insertions(+), 123 deletions(-)
diff --git a/be/src/vec/exec/vjdbc_connector.cpp
b/be/src/vec/exec/vjdbc_connector.cpp
index 6a34c0c311..5ded70ed2f 100644
--- a/be/src/vec/exec/vjdbc_connector.cpp
+++ b/be/src/vec/exec/vjdbc_connector.cpp
@@ -460,7 +460,20 @@ Status JdbcConnector::_convert_batch_result_set(JNIEnv*
env, jobject jcolumn_dat
address[1]);
break;
}
- case TYPE_CHAR:
+ case TYPE_CHAR: {
+ bool need_trim_spaces = false;
+ if ((_conn_param.table_type == TOdbcTableType::POSTGRESQL) ||
+ (_conn_param.table_type == TOdbcTableType::ORACLE)) {
+ need_trim_spaces = true;
+ }
+ auto column_string =
reinterpret_cast<vectorized::ColumnString*>(col_ptr);
+ address[1] =
reinterpret_cast<int64_t>(column_string->get_offsets().data());
+ auto chars_addres =
reinterpret_cast<int64_t>(&column_string->get_chars());
+ env->CallNonvirtualVoidMethod(_executor_obj, _executor_clazz,
_executor_get_char_result,
+ jcolumn_data, column_is_nullable,
num_rows, address[0],
+ address[1], chars_addres,
need_trim_spaces);
+ break;
+ }
case TYPE_STRING:
case TYPE_VARCHAR: {
auto column_string =
reinterpret_cast<vectorized::ColumnString*>(col_ptr);
@@ -591,6 +604,8 @@ Status JdbcConnector::_register_func_id(JNIEnv* env) {
JDBC_EXECUTOR_COPY_BATCH_SIGNATURE,
_executor_get_double_result));
RETURN_IF_ERROR(register_id(_executor_clazz, "copyBatchStringResult",
"(Ljava/lang/Object;ZIJJJ)V",
_executor_get_string_result));
+ RETURN_IF_ERROR(register_id(_executor_clazz, "copyBatchCharResult",
+ "(Ljava/lang/Object;ZIJJJZ)V",
_executor_get_char_result));
RETURN_IF_ERROR(register_id(_executor_clazz, "copyBatchDateResult",
JDBC_EXECUTOR_COPY_BATCH_SIGNATURE,
_executor_get_date_result));
diff --git a/be/src/vec/exec/vjdbc_connector.h
b/be/src/vec/exec/vjdbc_connector.h
index b7c8b6166a..fecedbb6fc 100644
--- a/be/src/vec/exec/vjdbc_connector.h
+++ b/be/src/vec/exec/vjdbc_connector.h
@@ -127,6 +127,7 @@ private:
jmethodID _executor_get_largeint_result;
jmethodID _executor_get_float_result;
jmethodID _executor_get_double_result;
+ jmethodID _executor_get_char_result;
jmethodID _executor_get_string_result;
jmethodID _executor_get_date_result;
jmethodID _executor_get_datev2_result;
diff --git a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
index d2bc7d9622..84f766456e 100644
--- a/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
+++ b/fe/java-udf/src/main/java/org/apache/doris/udf/JdbcExecutor.java
@@ -57,7 +57,7 @@ public class JdbcExecutor {
private List<String> resultColumnTypeNames = null;
private int baseTypeInt = 0;
private List<Object[]> block = null;
- private int bacthSizeNum = 0;
+ private int batchSizeNum = 0;
private int curBlockRows = 0;
private static final byte[] emptyBytes = new byte[0];
private DruidDataSource druidDataSource = null;
@@ -98,14 +98,11 @@ public class JdbcExecutor {
block = new ArrayList<>(columnCount);
for (int i = 0; i < columnCount; ++i) {
resultColumnTypeNames.add(resultSetMetaData.getColumnClassName(i + 1));
- Class<?> clazz =
Class.forName(resultSetMetaData.getColumnClassName(i + 1));
- block.add((Object[]) Array.newInstance(clazz, bacthSizeNum));
+ block.add((Object[]) Array.newInstance(Object.class,
batchSizeNum));
}
return columnCount;
} catch (SQLException e) {
throw new UdfRuntimeException("JDBC executor sql has error: ", e);
- } catch (ClassNotFoundException e) {
- throw new UdfRuntimeException("JDBC executor sql
ClassNotFoundException: ", e);
}
}
@@ -177,8 +174,6 @@ public class JdbcExecutor {
} while (curBlockRows < batchSize && resultSet.next());
} catch (SQLException e) {
throw new UdfRuntimeException("get next block failed: ", e);
- } catch (Exception e) {
- throw new UdfRuntimeException("unable to get next : ", e);
}
return block;
}
@@ -198,63 +193,6 @@ public class JdbcExecutor {
}
}
- public long convertDateToLong(Object obj, boolean isDateV2) {
- LocalDate date;
- if (obj instanceof LocalDate) {
- date = (LocalDate) obj;
- } else {
- date = ((Date) obj).toLocalDate();
- }
- if (isDateV2) {
- return UdfUtils.convertToDateV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth());
- }
- return UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
- 0, 0, 0, true);
- }
-
- public long convertDateTimeToLong(Object obj, boolean isDateTimeV2) throws
UdfRuntimeException {
- LocalDateTime date = null;
- // TODO: not for sure: https://bugs.mysql.com/bug.php?id=101413
- if (obj instanceof LocalDateTime) {
- date = (LocalDateTime) obj;
- } else if (obj instanceof java.sql.Timestamp) {
- date = ((java.sql.Timestamp) obj).toLocalDateTime();
- } else if (obj instanceof oracle.sql.TIMESTAMP) {
- try {
- date = ((oracle.sql.TIMESTAMP)
obj).timestampValue().toLocalDateTime();
- } catch (SQLException e) {
- throw new UdfRuntimeException("Convert oracle.sql.TIMESTAMP"
- + " to LocalDateTime failed: ", e);
- }
- }
- if (isDateTimeV2) {
- return UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
- date.getHour(), date.getMinute(), date.getSecond());
- }
- return UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
- date.getHour(), date.getMinute(), date.getSecond(), false);
- }
-
- public byte convertTinyIntToByte(Object obj) {
- byte res = 0;
- if (obj instanceof Integer) {
- res = ((Integer) obj).byteValue();
- } else if (obj instanceof Short) {
- res = ((Short) obj).byteValue();
- }
- return res;
- }
-
- public short convertSmallIntToShort(Object obj) {
- short res = 0;
- if (obj instanceof Integer) {
- res = ((Integer) obj).shortValue();
- } else if (obj instanceof Short) {
- res = (short) obj;
- }
- return res;
- }
-
public Object convertArrayToObject(Object obj, int idx) {
Object[] columnData = (Object[]) obj;
if (columnData[idx] instanceof String) {
@@ -290,7 +228,7 @@ public class JdbcExecutor {
stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
ResultSet.FETCH_FORWARD);
stmt.setFetchSize(batchSize);
- bacthSizeNum = batchSize;
+ batchSizeNum = batchSize;
} else {
stmt = conn.createStatement();
}
@@ -305,18 +243,71 @@ public class JdbcExecutor {
public void copyBatchBooleanResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr) {
- Boolean[] column = (Boolean[]) columnObj;
+ Object[] column = (Object[]) columnObj;
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putByte(columnAddr + i, column[i] ? (byte)
1 : 0);
+ UdfUtils.UNSAFE.putByte(columnAddr + i, (Boolean)
column[i] ? (byte) 1 : 0);
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putByte(columnAddr + i, column[i] ? (byte) 1 :
0);
+ UdfUtils.UNSAFE.putByte(columnAddr + i, (Boolean) column[i] ?
(byte) 1 : 0);
+ }
+ }
+ }
+
+ private void bigDecimalPutToByte(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ Short res = ((BigDecimal) column[i]).shortValueExact();
+ UdfUtils.UNSAFE.putByte(columnAddr + i, res.byteValue());
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ Short res = ((BigDecimal) column[i]).shortValueExact();
+ UdfUtils.UNSAFE.putByte(columnAddr + i, res.byteValue());
+ }
+ }
+ }
+
+ private void integerPutToByte(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ UdfUtils.UNSAFE.putByte(columnAddr + i, ((Integer)
column[i]).byteValue());
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ UdfUtils.UNSAFE.putByte(columnAddr + i, ((Integer)
column[i]).byteValue());
+ }
+ }
+ }
+
+ private void shortPutToByte(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ UdfUtils.UNSAFE.putByte(columnAddr + i, ((Short)
column[i]).byteValue());
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ UdfUtils.UNSAFE.putByte(columnAddr + i, ((Short)
column[i]).byteValue());
}
}
}
@@ -324,17 +315,62 @@ public class JdbcExecutor {
public void copyBatchTinyIntResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr) {
Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof BigDecimal) {
+ bigDecimalPutToByte(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Integer) {
+ integerPutToByte(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Short) {
+ shortPutToByte(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
+ private void bigDecimalPutToShort(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putByte(columnAddr + i,
convertTinyIntToByte(column[i]));
+ UdfUtils.UNSAFE.putShort(columnAddr + (i * 2L),
((BigDecimal) column[i]).shortValueExact());
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putByte(columnAddr + i,
convertTinyIntToByte(column[i]));
+ UdfUtils.UNSAFE.putShort(columnAddr + (i * 2L), ((BigDecimal)
column[i]).shortValueExact());
+ }
+ }
+ }
+
+ private void integerPutToShort(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ UdfUtils.UNSAFE.putShort(columnAddr + (i * 2L), ((Integer)
column[i]).shortValue());
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ UdfUtils.UNSAFE.putShort(columnAddr + (i * 2L), ((Integer)
column[i]).shortValue());
+ }
+ }
+ }
+
+ private void shortPutToShort(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ UdfUtils.UNSAFE.putShort(columnAddr + (i * 2L), (Short)
column[i]);
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ UdfUtils.UNSAFE.putShort(columnAddr + (i * 2L), (Short)
column[i]);
}
}
}
@@ -342,123 +378,283 @@ public class JdbcExecutor {
public void copyBatchSmallIntResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr) {
Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof BigDecimal) {
+ bigDecimalPutToShort(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Integer) {
+ integerPutToShort(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Short) {
+ shortPutToShort(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
+
+ private void bigDecimalPutToInt(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L),
((BigDecimal) column[i]).intValueExact());
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L), ((BigDecimal)
column[i]).intValueExact());
+ }
+ }
+ }
+
+ private void integerPutToInt(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putShort(columnAddr + (i * 2),
convertSmallIntToShort(column[i]));
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L), (Integer)
column[i]);
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putShort(columnAddr + (i * 2),
convertSmallIntToShort(column[i]));
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L), (Integer)
column[i]);
}
}
}
public void copyBatchIntResult(Object columnObj, boolean isNullable, int
numRows, long nullMapAddr,
long columnAddr) {
- Integer[] column = (Integer[]) columnObj;
+ Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof BigDecimal) {
+ bigDecimalPutToInt(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Integer) {
+ integerPutToInt(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
+ private void bigDecimalPutToLong(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putInt(columnAddr + (i * 4), (int)
column[i]);
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
((BigDecimal) column[i]).longValueExact());
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putInt(columnAddr + (i * 4), (int) column[i]);
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L), ((BigDecimal)
column[i]).longValueExact());
}
}
}
- public void copyBatchBigIntResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
+ private void longPutToLong(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
long columnAddr) {
- Long[] column = (Long[]) columnObj;
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8), (long)
column[i]);
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L), (Long)
column[i]);
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8), (long)
column[i]);
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L), (Long)
column[i]);
}
}
}
- public void copyBatchLargeIntResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
+ public void copyBatchBigIntResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
+ long columnAddr) {
+ Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof BigDecimal) {
+ bigDecimalPutToLong(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Long) {
+ longPutToLong(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
+ private void bigDecimalPutToBigInteger(Object[] column, boolean
isNullable, int numRows, long nullMapAddr,
+ long columnAddr) {
+ BigInteger[] data = new BigInteger[numRows];
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ data[i] = null;
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ data[i] = ((BigDecimal) column[i]).toBigInteger();
+ }
+ }
+ copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16);
+ }
+
+ private void bigIntegerPutToByte(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
long columnAddr) {
- BigInteger[] column = (BigInteger[]) columnObj;
if (isNullable == true) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- byte[] bytes =
UdfUtils.convertByteOrder(column[i].toByteArray());
+ BigInteger columnValue = (BigInteger) column[i];
+ byte[] bytes =
UdfUtils.convertByteOrder(columnValue.toByteArray());
byte[] value = new byte[16];
- if (column[i].signum() == -1) {
+ if (columnValue.signum() == -1) {
Arrays.fill(value, (byte) -1);
}
for (int index = 0; index < Math.min(bytes.length,
value.length); ++index) {
value[index] = bytes[index];
}
- UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET,
null, columnAddr + (i * 16), 16);
+ UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET,
null, columnAddr + (i * 16L), 16);
}
}
} else {
for (int i = 0; i < numRows; i++) {
- byte[] bytes =
UdfUtils.convertByteOrder(column[i].toByteArray());
+ BigInteger columnValue = (BigInteger) column[i];
+ byte[] bytes =
UdfUtils.convertByteOrder(columnValue.toByteArray());
byte[] value = new byte[16];
- if (column[i].signum() == -1) {
+ if (columnValue.signum() == -1) {
Arrays.fill(value, (byte) -1);
}
for (int index = 0; index < Math.min(bytes.length,
value.length); ++index) {
value[index] = bytes[index];
}
- UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET, null,
columnAddr + (i * 16), 16);
+ UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET, null,
columnAddr + (i * 16L), 16);
}
}
}
+ public void copyBatchLargeIntResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
+ long columnAddr) {
+ Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof BigDecimal) {
+ bigDecimalPutToBigInteger(column, isNullable, numRows,
nullMapAddr, columnAddr);
+ } else if (column[0] instanceof BigInteger) {
+ bigIntegerPutToByte(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
public void copyBatchFloatResult(Object columnObj, boolean isNullable, int
numRows, long nullMapAddr,
long columnAddr) {
- Float[] column = (Float[]) columnObj;
+ Object[] column = (Object[]) columnObj;
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ UdfUtils.UNSAFE.putFloat(columnAddr + (i * 4L), (Float)
column[i]);
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ UdfUtils.UNSAFE.putFloat(columnAddr + (i * 4L), (Float)
column[i]);
+ }
+ }
+ }
+
+ private void bigDecimalPutToDouble(Object[] column, boolean isNullable,
int numRows, long nullMapAddr,
+ long columnAddr) {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putFloat(columnAddr + (i * 4), (float)
column[i]);
+ UdfUtils.UNSAFE.putDouble(columnAddr + (i * 8L),
((BigDecimal) column[i]).doubleValue());
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putFloat(columnAddr + (i * 4), (float)
column[i]);
+ UdfUtils.UNSAFE.putDouble(columnAddr + (i * 8L), ((BigDecimal)
column[i]).doubleValue());
+ }
+ }
+ }
+
+
+ private void doublePutToDouble(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ UdfUtils.UNSAFE.putDouble(columnAddr + (i * 8L), (Double)
column[i]);
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ UdfUtils.UNSAFE.putDouble(columnAddr + (i * 8L), (Double)
column[i]);
}
}
}
public void copyBatchDoubleResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr) {
- Double[] column = (Double[]) columnObj;
+ Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof BigDecimal) {
+ bigDecimalPutToDouble(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Double) {
+ doublePutToDouble(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
+ //TODO: now array type need this function, can remove after refactor read
array type
+ public long convertDateToLong(Object obj, boolean isDateV2) {
+ LocalDate date;
+ if (obj instanceof LocalDate) {
+ date = (LocalDate) obj;
+ } else {
+ date = ((Date) obj).toLocalDate();
+ }
+ if (isDateV2) {
+ return UdfUtils.convertToDateV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth());
+ }
+ return UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
+ 0, 0, 0, true);
+ }
+
+ private void localDatePutToLong(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ LocalDate date = (LocalDate) column[i];
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), 0, 0, 0, true));
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ LocalDate date = (LocalDate) column[i];
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), 0, 0, 0, true));
+ }
+ }
+ }
+
+ private void datePutToLong(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putDouble(columnAddr + (i * 8), (double)
column[i]);
+ LocalDate date = ((Date) column[i]).toLocalDate();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), 0, 0, 0, true));
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putDouble(columnAddr + (i * 8), (double)
column[i]);
+ LocalDate date = ((Date) column[i]).toLocalDate();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), 0, 0, 0, true));
}
}
}
@@ -466,17 +662,53 @@ public class JdbcExecutor {
public void copyBatchDateResult(Object columnObj, boolean isNullable, int
numRows, long nullMapAddr,
long columnAddr) {
Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof LocalDate) {
+ localDatePutToLong(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Date) {
+ datePutToLong(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
+ private void localDatePutToInt(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ LocalDate date = (LocalDate) column[i];
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L),
+ UdfUtils.convertToDateV2(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth()));
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ LocalDate date = (LocalDate) column[i];
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L),
+ UdfUtils.convertToDateV2(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth()));
+ }
+ }
+ }
+
+ private void datePutToInt(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8),
convertDateToLong(column[i], false));
+ LocalDate date = ((Date) column[i]).toLocalDate();
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L),
+ UdfUtils.convertToDateV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth()));
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8),
convertDateToLong(column[i], false));
+ LocalDate date = ((Date) column[i]).toLocalDate();
+ UdfUtils.UNSAFE.putInt(columnAddr + (i * 4L),
+ UdfUtils.convertToDateV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth()));
}
}
}
@@ -484,60 +716,264 @@ public class JdbcExecutor {
public void copyBatchDateV2Result(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr) {
Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof LocalDate) {
+ localDatePutToInt(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof Date) {
+ datePutToInt(column, isNullable, numRows, nullMapAddr, columnAddr);
+ }
+ }
+
+ //TODO: now array type need this function, can remove after refactor read
array type
+ public long convertDateTimeToLong(Object obj, boolean isDateTimeV2) throws
UdfRuntimeException {
+ LocalDateTime date = null;
+ // TODO: not for sure: https://bugs.mysql.com/bug.php?id=101413
+ if (obj instanceof LocalDateTime) {
+ date = (LocalDateTime) obj;
+ } else if (obj instanceof java.sql.Timestamp) {
+ date = ((java.sql.Timestamp) obj).toLocalDateTime();
+ } else if (obj instanceof oracle.sql.TIMESTAMP) {
+ try {
+ date = ((oracle.sql.TIMESTAMP)
obj).timestampValue().toLocalDateTime();
+ } catch (SQLException e) {
+ throw new UdfRuntimeException("Convert oracle.sql.TIMESTAMP"
+ + " to LocalDateTime failed: ", e);
+ }
+ }
+ if (isDateTimeV2) {
+ return UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
+ date.getHour(), date.getMinute(), date.getSecond());
+ }
+ return UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
+ date.getHour(), date.getMinute(), date.getSecond(), false);
+ }
+
+ private void localDateTimePutToLong(Object[] column, boolean isNullable,
int numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ LocalDateTime date = (LocalDateTime) column[i];
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(),
+ date.getSecond(), false));
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ LocalDateTime date = (LocalDateTime) column[i];
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(),
+ date.getSecond(), false));
+ }
+ }
+ }
+
+ private void timestampPutToLong(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ LocalDateTime date = ((java.sql.Timestamp)
column[i]).toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(), date.getSecond(), false));
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ LocalDateTime date = ((java.sql.Timestamp)
column[i]).toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
+ date.getHour(), date.getMinute(),
date.getSecond(), false));
+ }
+ }
+ }
+
+ private void oracleTimetampPutToLong(Object[] column, boolean isNullable,
int numRows,
+ long nullMapAddr,
+ long columnAddr) throws SQLException {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putInt(columnAddr + (i * 4), (int)
convertDateToLong(column[i], true));
+ LocalDateTime date = ((oracle.sql.TIMESTAMP)
column[i]).timestampValue().toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(), date.getSecond(), false));
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putInt(columnAddr + (i * 4), (int)
convertDateToLong(column[i], true));
+ LocalDateTime date = ((oracle.sql.TIMESTAMP)
column[i]).timestampValue().toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTime(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
+ date.getHour(), date.getMinute(),
date.getSecond(), false));
}
}
}
public void copyBatchDateTimeResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
- long columnAddr) throws UdfRuntimeException {
+ long columnAddr) throws SQLException {
Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof LocalDateTime) {
+ localDateTimePutToLong(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof java.sql.Timestamp) {
+ timestampPutToLong(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof oracle.sql.TIMESTAMP) {
+ oracleTimetampPutToLong(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ }
+ }
+
+ private void localDateTimePutToLongV2(Object[] column, boolean isNullable,
int numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ LocalDateTime date = (LocalDateTime) column[i];
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(),
+ date.getSecond()));
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ LocalDateTime date = (LocalDateTime) column[i];
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(),
+ date.getSecond()));
+ }
+ }
+ }
+
+ private void timestampPutToLongV2(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long columnAddr) {
+ if (isNullable) {
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] == null) {
+ UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
+ } else {
+ LocalDateTime date = ((java.sql.Timestamp)
column[i]).toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(), date.getSecond()));
+ }
+ }
+ } else {
+ for (int i = 0; i < numRows; i++) {
+ LocalDateTime date = ((java.sql.Timestamp)
column[i]).toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
+ date.getHour(), date.getMinute(),
date.getSecond()));
+ }
+ }
+ }
+
+ private void oracleTimetampPutToLongV2(Object[] column, boolean
isNullable, int numRows,
+ long nullMapAddr, long columnAddr) throws SQLException {
if (isNullable) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8),
convertDateTimeToLong(column[i], false));
+ LocalDateTime date = ((oracle.sql.TIMESTAMP)
column[i]).timestampValue().toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(),
+ date.getDayOfMonth(), date.getHour(),
date.getMinute(), date.getSecond()));
}
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8),
convertDateTimeToLong(column[i], false));
+ LocalDateTime date = ((oracle.sql.TIMESTAMP)
column[i]).timestampValue().toLocalDateTime();
+ UdfUtils.UNSAFE.putLong(columnAddr + (i * 8L),
+ UdfUtils.convertToDateTimeV2(date.getYear(),
date.getMonthValue(), date.getDayOfMonth(),
+ date.getHour(), date.getMinute(),
date.getSecond()));
}
}
}
public void copyBatchDateTimeV2Result(Object columnObj, boolean
isNullable, int numRows, long nullMapAddr,
- long columnAddr) throws UdfRuntimeException {
+ long columnAddr) throws SQLException {
Object[] column = (Object[]) columnObj;
- if (isNullable) {
+ if (column[0] instanceof LocalDateTime) {
+ localDateTimePutToLongV2(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof java.sql.Timestamp) {
+ timestampPutToLongV2(column, isNullable, numRows, nullMapAddr,
columnAddr);
+ } else if (column[0] instanceof oracle.sql.TIMESTAMP) {
+ oracleTimetampPutToLongV2(column, isNullable, numRows,
nullMapAddr, columnAddr);
+ }
+ }
+
+ public String trimSpaces(String str) {
+ int end = str.length() - 1;
+ while (end >= 0 && str.charAt(end) == ' ') {
+ end--;
+ }
+ return str.substring(0, end + 1);
+ }
+
+ public void copyBatchCharResult(Object columnObj, boolean isNullable, int
numRows, long nullMapAddr,
+ long offsetsAddr, long charsAddr, boolean needTrimSpaces) {
+ if (needTrimSpaces == true) {
+ Object[] column = (Object[]) columnObj;
+ for (int i = 0; i < numRows; i++) {
+ if (column[i] != null) {
+ column[i] = trimSpaces((String) column[i]);
+ }
+ }
+ copyBatchStringResult(column, isNullable, numRows, nullMapAddr,
offsetsAddr, charsAddr);
+ } else {
+ copyBatchStringResult(columnObj, isNullable, numRows, nullMapAddr,
offsetsAddr, charsAddr);
+ }
+ }
+
+ private void objectPutToString(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
+ long offsetsAddr, long charsAddr) {
+ int[] offsets = new int[numRows];
+ byte[][] byteRes = new byte[numRows][];
+ int offset = 0;
+ if (isNullable == true) {
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
+ byteRes[i] = emptyBytes;
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8),
convertDateTimeToLong(column[i], true));
+ byteRes[i] =
column[i].toString().getBytes(StandardCharsets.UTF_8);
}
+ offset += byteRes[i].length;
+ offsets[i] = offset;
}
} else {
for (int i = 0; i < numRows; i++) {
- UdfUtils.UNSAFE.putLong(columnAddr + (i * 8),
convertDateTimeToLong(column[i], true));
+ byteRes[i] =
column[i].toString().getBytes(StandardCharsets.UTF_8);
+ offset += byteRes[i].length;
+ offsets[i] = offset;
+ }
+ }
+ byte[] bytes = new byte[offsets[numRows - 1]];
+ long bytesAddr = JNINativeMethod.resizeColumn(charsAddr,
offsets[numRows - 1]);
+ int dst = 0;
+ for (int i = 0; i < numRows; i++) {
+ for (int j = 0; j < byteRes[i].length; j++) {
+ bytes[dst++] = byteRes[i][j];
}
}
+ UdfUtils.copyMemory(offsets, UdfUtils.INT_ARRAY_OFFSET, null,
offsetsAddr, numRows * 4L);
+ UdfUtils.copyMemory(bytes, UdfUtils.BYTE_ARRAY_OFFSET, null,
bytesAddr, offsets[numRows - 1]);
}
- public void copyBatchStringResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
+ private void stringPutToString(Object[] column, boolean isNullable, int
numRows, long nullMapAddr,
long offsetsAddr, long charsAddr) {
- String[] column = (String[]) columnObj;
int[] offsets = new int[numRows];
byte[][] byteRes = new byte[numRows][];
int offset = 0;
@@ -547,14 +983,14 @@ public class JdbcExecutor {
byteRes[i] = emptyBytes;
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- byteRes[i] = column[i].getBytes(StandardCharsets.UTF_8);
+ byteRes[i] = ((String)
column[i]).getBytes(StandardCharsets.UTF_8);
}
offset += byteRes[i].length;
offsets[i] = offset;
}
} else {
for (int i = 0; i < numRows; i++) {
- byteRes[i] = column[i].getBytes(StandardCharsets.UTF_8);
+ byteRes[i] = ((String)
column[i]).getBytes(StandardCharsets.UTF_8);
offset += byteRes[i].length;
offsets[i] = offset;
}
@@ -571,16 +1007,28 @@ public class JdbcExecutor {
UdfUtils.copyMemory(bytes, UdfUtils.BYTE_ARRAY_OFFSET, null,
bytesAddr, offsets[numRows - 1]);
}
+ public void copyBatchStringResult(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
+ long offsetsAddr, long charsAddr) {
+ Object[] column = (Object[]) columnObj;
+ if (column[0] instanceof String) {
+ stringPutToString(column, isNullable, numRows, nullMapAddr,
offsetsAddr, charsAddr);
+ } else {
+ //object like in pg type point, polygon, jsonb..... get object is
org.postgresql.util.PGobject.....
+ //here object put to string, so the object must have impl
toString() function
+ objectPutToString(column, isNullable, numRows, nullMapAddr,
offsetsAddr, charsAddr);
+ }
+ }
+
public void copyBatchDecimalV2Result(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr) {
- BigDecimal[] column = (BigDecimal[]) columnObj;
+ Object[] column = (Object[]) columnObj;
BigInteger[] data = new BigInteger[numRows];
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
data[i] = null;
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- data[i] = column[i].setScale(9,
RoundingMode.HALF_EVEN).unscaledValue();
+ data[i] = ((BigDecimal) column[i]).setScale(9,
RoundingMode.HALF_EVEN).unscaledValue();
}
}
copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16);
@@ -588,14 +1036,14 @@ public class JdbcExecutor {
public void copyBatchDecimal32Result(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr, int scale) {
- BigDecimal[] column = (BigDecimal[]) columnObj;
+ Object[] column = (Object[]) columnObj;
BigInteger[] data = new BigInteger[numRows];
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
data[i] = null;
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- data[i] = column[i].setScale(scale,
RoundingMode.HALF_EVEN).unscaledValue();
+ data[i] = ((BigDecimal) column[i]).setScale(scale,
RoundingMode.HALF_EVEN).unscaledValue();
}
}
copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 4);
@@ -603,14 +1051,14 @@ public class JdbcExecutor {
public void copyBatchDecimal64Result(Object columnObj, boolean isNullable,
int numRows, long nullMapAddr,
long columnAddr, int scale) {
- BigDecimal[] column = (BigDecimal[]) columnObj;
+ Object[] column = (Object[]) columnObj;
BigInteger[] data = new BigInteger[numRows];
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
data[i] = null;
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- data[i] = column[i].setScale(scale,
RoundingMode.HALF_EVEN).unscaledValue();
+ data[i] = ((BigDecimal) column[i]).setScale(scale,
RoundingMode.HALF_EVEN).unscaledValue();
}
}
copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 8);
@@ -618,22 +1066,21 @@ public class JdbcExecutor {
public void copyBatchDecimal128Result(Object columnObj, boolean
isNullable, int numRows, long nullMapAddr,
long columnAddr, int scale) {
- BigDecimal[] column = (BigDecimal[]) columnObj;
+ Object[] column = (Object[]) columnObj;
BigInteger[] data = new BigInteger[numRows];
for (int i = 0; i < numRows; i++) {
if (column[i] == null) {
data[i] = null;
UdfUtils.UNSAFE.putByte(nullMapAddr + i, (byte) 1);
} else {
- data[i] = column[i].setScale(scale,
RoundingMode.HALF_EVEN).unscaledValue();
+ data[i] = ((BigDecimal) column[i]).setScale(scale,
RoundingMode.HALF_EVEN).unscaledValue();
}
}
copyBatchDecimalResult(data, isNullable, numRows, columnAddr, 16);
}
- public void copyBatchDecimalResult(Object columnObj, boolean isNullable,
int numRows,
+ private void copyBatchDecimalResult(BigInteger[] column, boolean
isNullable, int numRows,
long columnAddr, int typeLen) {
- BigInteger[] column = (BigInteger[]) columnObj;
if (isNullable == true) {
for (int i = 0; i < numRows; i++) {
if (column[i] != null) {
@@ -645,7 +1092,8 @@ public class JdbcExecutor {
for (int index = 0; index < Math.min(bytes.length,
value.length); ++index) {
value[index] = bytes[index];
}
- UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET,
null, columnAddr + (i * typeLen), typeLen);
+ UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET,
null, columnAddr + ((long) i * typeLen),
+ typeLen);
}
}
} else {
@@ -658,7 +1106,8 @@ public class JdbcExecutor {
for (int index = 0; index < Math.min(bytes.length,
value.length); ++index) {
value[index] = bytes[index];
}
- UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET, null,
columnAddr + (i * typeLen), typeLen);
+ UdfUtils.copyMemory(value, UdfUtils.BYTE_ARRAY_OFFSET, null,
columnAddr + ((long) i * typeLen),
+ typeLen);
}
}
}
diff --git a/regression-test/suites/jdbc_p0/test_jdbc_query_mysql.groovy
b/regression-test/suites/jdbc_p0/test_jdbc_query_mysql.groovy
index 778291a401..ed9aabcc26 100644
--- a/regression-test/suites/jdbc_p0/test_jdbc_query_mysql.groovy
+++ b/regression-test/suites/jdbc_p0/test_jdbc_query_mysql.groovy
@@ -795,6 +795,7 @@ suite("test_jdbc_query_mysql", "p0") {
FROM ( SELECT id AS a, id % 3 AS b FROM
${exMysqlTable}) t1
JOIN ${exMysqlTable} t2 ON t1.a = t2.id GROUP BY
t1.a) o
ON l.b = o.d AND l.a = o.a order by l.a desc limit
3"""
+ // this pr fixed, wait for merge:
https://github.com/apache/doris/pull/16442
order_qt_sql48 """ SELECT x, y, COUNT(*) as c FROM (SELECT k8, 0 AS x
FROM $jdbcMysql57Table1) a
JOIN (SELECT k8, 1 AS y FROM $jdbcMysql57Table1) b
ON a.k8 = b.k8 group by x, y order by c desc limit 3 """
order_qt_sql49 """ SELECT * FROM (SELECT * FROM $jdbcMysql57Table1
WHERE k8 % 120 > 110) l
@@ -934,7 +935,7 @@ suite("test_jdbc_query_mysql", "p0") {
order_qt_sql111 """ SELECT rank() OVER () FROM (SELECT k8 FROM
$jdbcMysql57Table1 LIMIT 10) as t LIMIT 3 """
order_qt_sql112 """ SELECT k7, count(DISTINCT k8) FROM
$jdbcMysql57Table1 WHERE k8 > 110 GROUP BY GROUPING SETS ((), (k7)) """
-
+ // TODO: check this, maybe caused by datasource in JDBC
// test alter resource
sql """alter resource $jdbcResourceMysql57 properties("password" =
"1234567")"""
test {
diff --git a/regression-test/suites/jdbc_p0/test_jdbc_query_pg.groovy
b/regression-test/suites/jdbc_p0/test_jdbc_query_pg.groovy
index 60c6c65ff9..9e8a451069 100644
--- a/regression-test/suites/jdbc_p0/test_jdbc_query_pg.groovy
+++ b/regression-test/suites/jdbc_p0/test_jdbc_query_pg.groovy
@@ -70,7 +70,7 @@ suite("test_jdbc_query_pg", "p0") {
);
"""
order_qt_sql1 """select count(*) from $jdbcPg14Table1"""
- order_qt_sql2 """select * from $jdbcPg14Table1"""
+ order_qt_sql2 """select * from $jdbcPg14Table1 order by
k1,k2,k3,k4,k5,k6,k7,k8,k9,k10;"""
// test for : doris query external table which is pg table's view
@@ -498,6 +498,7 @@ suite("test_jdbc_query_pg", "p0") {
FROM ( SELECT id AS a, id % 3 AS b FROM
${dorisExTable1}) t1
JOIN ${dorisExTable1} t2 ON t1.a = t2.id GROUP BY
t1.a) o
ON l.b = o.d AND l.a = o.a order by l.a desc limit
3"""
+ // this pr fixed, wait for merge:
https://github.com/apache/doris/pull/16442
order_qt_sql48 """ SELECT x, y, COUNT(*) as c FROM (SELECT k8, 0 AS x
FROM $jdbcPg14Table1) a
JOIN (SELECT k8, 1 AS y FROM $jdbcPg14Table1) b ON
a.k8 = b.k8 group by x, y order by c desc limit 3 """
order_qt_sql49 """ SELECT * FROM (SELECT * FROM $jdbcPg14Table1 WHERE
k8 % 120 > 110) l
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]