3030import tech .ydb .jdbc .query .YdbPreparedQuery ;
3131import tech .ydb .jdbc .query .YdbQuery ;
3232import tech .ydb .jdbc .query .params .BatchedQuery ;
33+ import tech .ydb .jdbc .query .params .BulkUpsertQuery ;
3334import tech .ydb .jdbc .query .params .InMemoryQuery ;
3435import tech .ydb .jdbc .query .params .PreparedQuery ;
3536import tech .ydb .jdbc .settings .YdbClientProperties ;
@@ -350,16 +351,23 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
350351 }
351352 }
352353
353- if (query .getType () == QueryType .EXPLAIN_QUERY || query .getType () == QueryType .SCHEME_QUERY ) {
354+ QueryType type = query .getType ();
355+
356+ if (type == QueryType .BULK_QUERY ) {
357+ if (query .getYqlBatcher () == null || query .getYqlBatcher ().isInsert ()) {
358+ throw new SQLException (YdbConst .BULKS_UNSUPPORTED );
359+ }
360+ }
361+
362+ if (type == QueryType .EXPLAIN_QUERY || type == QueryType .SCHEME_QUERY ) {
354363 return new InMemoryQuery (query , queryOptions .isDeclareJdbcParameters ());
355364 }
356365
357- if (query .getYqlBatcher () != null && mode == YdbPrepareMode .AUTO ) {
366+ if (query .getYqlBatcher () != null && (mode == YdbPrepareMode .AUTO || type == QueryType .BULK_QUERY )) {
367+ String tableName = query .getYqlBatcher ().getTableName ();
368+ String tablePath = tableName .startsWith ("/" ) ? tableName : getDatabase () + "/" + tableName ;
358369 Map <String , Type > types = queryParamsCache .getIfPresent (query .getOriginQuery ());
359370 if (types == null ) {
360- String tableName = query .getYqlBatcher ().getTableName ();
361- String tablePath = tableName .startsWith ("/" ) ? tableName : getDatabase () + "/" + tableName ;
362-
363371 DescribeTableSettings settings = withDefaultTimeout (new DescribeTableSettings ());
364372 Result <TableDescription > result = retryCtx .supplyResult (
365373 session -> session .describeTable (tablePath , settings )
@@ -370,8 +378,16 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
370378 types = descrtiption .getColumns ().stream ()
371379 .collect (Collectors .toMap (TableColumn ::getName , TableColumn ::getType ));
372380 queryParamsCache .put (query .getOriginQuery (), types );
381+ } else {
382+ if (type == QueryType .BULK_QUERY ) {
383+ throw new SQLException (YdbConst .BULKS_DESCRIBE_ERROR + result .getStatus ());
384+ }
373385 }
374386 }
387+ if (type == QueryType .BULK_QUERY ) {
388+ return BulkUpsertQuery .build (tablePath , query .getYqlBatcher ().getColumns (), types );
389+ }
390+
375391 if (types != null ) {
376392 BatchedQuery params = BatchedQuery .createAutoBatched (query .getYqlBatcher (), types );
377393 if (params != null ) {
0 commit comments