Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.TableProperty;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PhoenixArray;
import org.apache.phoenix.util.SchemaUtil;

import javax.inject.Inject;

import java.io.IOException;
import java.sql.Array;
import java.sql.Connection;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -762,8 +762,15 @@ private static ObjectReadFunction arrayReadFunction(ConnectorSession session, Ty
private static ObjectWriteFunction arrayWriteFunction(ConnectorSession session, Type elementType, String elementJdbcTypeName)
{
return ObjectWriteFunction.of(Block.class, (statement, index, block) -> {
Array jdbcArray = statement.getConnection().createArrayOf(elementJdbcTypeName, getJdbcObjectArray(session, elementType, block));
statement.setArray(index, jdbcArray);
Object[] jdbcObjectArray = getJdbcObjectArray(session, elementType, block);
PhoenixArray phoenixArray = (PhoenixArray) statement.getConnection().createArrayOf(elementJdbcTypeName, jdbcObjectArray);
for (int i = 0; i < jdbcObjectArray.length; i++) {
if (jdbcObjectArray[i] == null && phoenixArray.getElement(i) != null) {
// TODO (https://github.com/trinodb/trino/issues/6421) Prevent writing incorrect results due to Phoenix JDBC driver bug
throw new TrinoException(PHOENIX_QUERY_ERROR, format("Phoenix JDBC driver replaced 'null' with '%s' at index %s in %s", phoenixArray.getElement(i), i + 1, phoenixArray));
}
}
statement.setArray(index, phoenixArray);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ public void testInsertArray()
{
assertThatThrownBy(super::testInsertArray)
// TODO (https://github.com/trinodb/trino/issues/6421) array with double null stored as array with 0
.hasMessageContaining("Actual rows (up to 100 of 1 extra rows shown, 2 rows in total):\n" +
" [0.0, null]\n" +
"Expected rows (up to 100 of 1 missing rows shown, 2 rows in total):\n" +
" [null, null]");
.hasMessage("Phoenix JDBC driver replaced 'null' with '0.0' at index 1 in [0.0]");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.TableProperty;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PhoenixArray;
import org.apache.phoenix.util.SchemaUtil;

import javax.inject.Inject;

import java.io.IOException;
import java.sql.Array;
import java.sql.Connection;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -754,8 +754,15 @@ private static ObjectReadFunction arrayReadFunction(ConnectorSession session, Ty
private static ObjectWriteFunction arrayWriteFunction(ConnectorSession session, Type elementType, String elementJdbcTypeName)
{
return ObjectWriteFunction.of(Block.class, (statement, index, block) -> {
Array jdbcArray = statement.getConnection().createArrayOf(elementJdbcTypeName, getJdbcObjectArray(session, elementType, block));
statement.setArray(index, jdbcArray);
Object[] jdbcObjectArray = getJdbcObjectArray(session, elementType, block);
PhoenixArray phoenixArray = (PhoenixArray) statement.getConnection().createArrayOf(elementJdbcTypeName, jdbcObjectArray);
for (int i = 0; i < jdbcObjectArray.length; i++) {
if (jdbcObjectArray[i] == null && phoenixArray.getElement(i) != null) {
// TODO (https://github.com/trinodb/trino/issues/6421) Prevent writing incorrect results due to Phoenix JDBC driver bug
throw new TrinoException(PHOENIX_QUERY_ERROR, format("Phoenix JDBC driver replaced 'null' with '%s' at index %s in %s", phoenixArray.getElement(i), i + 1, phoenixArray));
}
}
statement.setArray(index, phoenixArray);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ public void testInsertArray()
{
assertThatThrownBy(super::testInsertArray)
// TODO (https://github.com/trinodb/trino/issues/6421) array with double null stored as array with 0
.hasMessageContaining("Actual rows (up to 100 of 1 extra rows shown, 2 rows in total):\n" +
" [0.0, null]\n" +
"Expected rows (up to 100 of 1 missing rows shown, 2 rows in total):\n" +
" [null, null]");
.hasMessage("Phoenix JDBC driver replaced 'null' with '0.0' at index 1 in [0.0]");
}

@Override
Expand Down