|
24 | 24 | import tech.ydb.core.settings.BaseRequestSettings; |
25 | 25 | import tech.ydb.jdbc.YdbConst; |
26 | 26 | import tech.ydb.jdbc.YdbPrepareMode; |
| 27 | +import tech.ydb.jdbc.YdbTracer; |
27 | 28 | import tech.ydb.jdbc.exception.ExceptionFactory; |
28 | 29 | import tech.ydb.jdbc.query.QueryType; |
29 | 30 | import tech.ydb.jdbc.query.YdbPreparedQuery; |
|
45 | 46 | import tech.ydb.table.TableClient; |
46 | 47 | import tech.ydb.table.description.TableDescription; |
47 | 48 | import tech.ydb.table.impl.PooledTableClient; |
| 49 | +import tech.ydb.table.query.DataQuery; |
48 | 50 | import tech.ydb.table.query.ExplainDataQueryResult; |
49 | 51 | import tech.ydb.table.rpc.grpc.GrpcTableRpc; |
50 | 52 | import tech.ydb.table.settings.DescribeTableSettings; |
@@ -393,11 +395,20 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode) |
393 | 395 | String tablePath = joined(getPrefixPath(), query.getYqlBatcher().getTableName()); |
394 | 396 | TableDescription description = tableDescribeCache.getIfPresent(tablePath); |
395 | 397 | if (description == null) { |
| 398 | + YdbTracer tracer = config.isTxTracedEnabled() ? YdbTracer.current() : null; |
| 399 | + if (tracer != null) { |
| 400 | + tracer.trace("--> describe table"); |
| 401 | + tracer.traceRequest(tablePath); |
| 402 | + } |
396 | 403 | DescribeTableSettings settings = withDefaultTimeout(new DescribeTableSettings()); |
397 | 404 | Result<TableDescription> result = retryCtx.supplyResult( |
398 | 405 | session -> session.describeTable(tablePath, settings) |
399 | 406 | ).join(); |
400 | 407 |
|
| 408 | + if (tracer != null) { |
| 409 | + tracer.trace("<-- " + result.getStatus()); |
| 410 | + } |
| 411 | + |
401 | 412 | if (result.isSuccess()) { |
402 | 413 | description = result.getValue(); |
403 | 414 | tableDescribeCache.put(query.getOriginQuery(), description); |
@@ -429,12 +440,29 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode) |
429 | 440 | try { |
430 | 441 | Map<String, Type> types = queryParamsCache.getIfPresent(query.getOriginQuery()); |
431 | 442 | if (types == null) { |
432 | | - String yql = query.getPreparedYql(); |
| 443 | + String yql = prefixPragma + query.getPreparedYql(); |
| 444 | + YdbTracer tracer = config.isTxTracedEnabled() ? YdbTracer.current() : null; |
| 445 | + if (tracer != null) { |
| 446 | + tracer.trace("--> prepare data query"); |
| 447 | + tracer.traceRequest(yql); |
| 448 | + } |
| 449 | + |
433 | 450 | PrepareDataQuerySettings settings = withDefaultTimeout(new PrepareDataQuerySettings()); |
434 | | - types = retryCtx.supplyResult(session -> session.prepareDataQuery(yql, settings)) |
435 | | - .join() |
436 | | - .getValue() |
437 | | - .types(); |
| 451 | + Result<DataQuery> result = retryCtx.supplyResult( |
| 452 | + session -> session.prepareDataQuery(yql, settings) |
| 453 | + ).join(); |
| 454 | + |
| 455 | + if (tracer != null) { |
| 456 | + tracer.trace("<-- " + result.getStatus()); |
| 457 | + } |
| 458 | + if (!result.isSuccess()) { |
| 459 | + if (tracer != null) { |
| 460 | + tracer.close(); |
| 461 | + } |
| 462 | + throw new SQLException(YdbConst.UNABLE_PREPARE_STATEMENT + result.getStatus()); |
| 463 | + } |
| 464 | + |
| 465 | + types = result.getValue().types(); |
438 | 466 | queryParamsCache.put(query.getOriginQuery(), types); |
439 | 467 | } |
440 | 468 |
|
|
0 commit comments