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
9 changes: 5 additions & 4 deletions jdbc/src/main/java/tech/ydb/jdbc/context/YdbContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
}

QueryType type = query.getType();
YqlBatcher batcher = query.getYqlBatcher();

if (type == QueryType.BULK_QUERY) {
if (query.getYqlBatcher() == null || query.getYqlBatcher().getCommand() != YqlBatcher.Cmd.UPSERT) {
if (batcher == null || batcher.getCommand() != YqlBatcher.Cmd.UPSERT) {
throw new SQLException(YdbConst.BULKS_UNSUPPORTED);
}
}
Expand All @@ -441,8 +442,8 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
return new InMemoryQuery(query, queryOptions.isDeclareJdbcParameters());
}

if (query.getYqlBatcher() != null && (mode == YdbPrepareMode.AUTO || type == QueryType.BULK_QUERY)) {
String tablePath = joined(getPrefixPath(), query.getYqlBatcher().getTableName());
if (batcher != null && (mode == YdbPrepareMode.AUTO || type == QueryType.BULK_QUERY)) {
String tablePath = joined(getPrefixPath(), batcher.getTableName());
TableDescription description = tableDescribeCache.getIfPresent(tablePath);
if (description == null) {
YdbTracer tracer = getTracer();
Expand All @@ -469,7 +470,7 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
if (query.getReturning() != null) {
throw new SQLException(YdbConst.BULK_NOT_SUPPORT_RETURNING);
}
return BulkUpsertQuery.build(types, tablePath, query.getYqlBatcher().getColumns(), description);
return BulkUpsertQuery.build(types, tablePath, batcher.getColumns(), description);
}

if (description != null) {
Expand Down
6 changes: 3 additions & 3 deletions jdbc/src/main/java/tech/ydb/jdbc/impl/BaseYdbResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private ValueReader readValue(int columnIndex) throws SQLException {

ValueReader value = getValue(columnIndex - 1);
ColumnInfo type = columns[columnIndex - 1];
wasNull = type.isNull() || (type.isOptional() && !value.isOptionalItemPresent());
wasNull = type == null || type.isNull() || (type.isOptional() && !value.isOptionalItemPresent());
return value;
}

Expand Down Expand Up @@ -594,10 +594,10 @@ public Value<?> getNativeColumn(int columnIndex) throws SQLException {
if (wasNull) {
return null;
}
while (value.getType().getKind() == Type.Kind.OPTIONAL) {
while (value != null && value.getType().getKind() == Type.Kind.OPTIONAL) {
value = value.getOptionalItem();
}
return value.getValue();
return value == null ? null : value.getValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ public static BatchedQuery createAutoBatched(YdbTypes types, YdbQuery query, Tab
throws SQLException {

YqlBatcher batcher = query.getYqlBatcher();
if (batcher == null) {
return null;
}

// DELETE and UPDATE may be batched only if WHERE contains only primary key columns
if (batcher.getCommand() == YqlBatcher.Cmd.DELETE || batcher.getCommand() == YqlBatcher.Cmd.UPDATE) {
Expand Down