-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added impelemntation and tests of query analyzer
- Loading branch information
Showing
8 changed files
with
332 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package tech.ydb.jdbc.context; | ||
|
||
import java.util.Collection; | ||
import java.util.concurrent.atomic.LongAdder; | ||
|
||
import tech.ydb.core.Status; | ||
import tech.ydb.jdbc.common.FixedResultSetFactory; | ||
import tech.ydb.jdbc.query.YdbQuery; | ||
import tech.ydb.table.result.ResultSetReader; | ||
|
||
/** | ||
* | ||
* @author Aleksandr Gorshenin | ||
*/ | ||
public class QueryStat { | ||
public static final String QUERY = "print_jdbc_stats();"; | ||
|
||
private static final FixedResultSetFactory STATS_RS_FACTORY = FixedResultSetFactory.newBuilder() | ||
.addTextColumn("sql") | ||
.addBooleanColumn("is_fullscan") | ||
.addLongColumn("executed") | ||
.addTextColumn("yql") | ||
.addTextColumn("ast") | ||
.addTextColumn("plan") | ||
.build(); | ||
|
||
private final String originSQL; | ||
private final String preparedYQL; | ||
|
||
private final String ast; | ||
private final String plan; | ||
private final LongAdder usage; | ||
private final boolean isFullScan; | ||
|
||
public QueryStat(YdbQuery query, String ast, String plan) { | ||
this.originSQL = query.getOriginQuery(); | ||
this.preparedYQL = query.getPreparedYql(); | ||
this.ast = ast; | ||
this.plan = plan; | ||
this.usage = new LongAdder(); | ||
this.isFullScan = plan.contains("\"Node Type\":\"TableFullScan\""); | ||
} | ||
|
||
public QueryStat(YdbQuery query, Status error) { | ||
this.originSQL = query.getOriginQuery(); | ||
this.preparedYQL = query.getPreparedYql(); | ||
this.ast = error.toString(); | ||
this.plan = error.toString(); | ||
this.usage = new LongAdder(); | ||
this.isFullScan = false; | ||
} | ||
|
||
public long getUsageCounter() { | ||
return usage.longValue(); | ||
} | ||
|
||
public String getOriginSQL() { | ||
return originSQL; | ||
} | ||
|
||
public String getPreparedYQL() { | ||
return preparedYQL; | ||
} | ||
|
||
public String getAat() { | ||
return ast; | ||
} | ||
|
||
public String getPlan() { | ||
return plan; | ||
} | ||
|
||
public boolean isFullScan() { | ||
return isFullScan; | ||
} | ||
|
||
public void incrementUsage() { | ||
this.usage.increment(); | ||
} | ||
|
||
public static ResultSetReader toResultSetReader(Collection<QueryStat> stats) { | ||
FixedResultSetFactory.ResultSetBuilder builder = STATS_RS_FACTORY.createResultSet(); | ||
for (QueryStat stat: stats) { | ||
builder.newRow() | ||
.withTextValue("sql", stat.originSQL) | ||
.withBoolValue("is_fullscan", stat.isFullScan) | ||
.withLongValue("executed", stat.usage.longValue()) | ||
.withTextValue("yql", stat.preparedYQL) | ||
.withTextValue("ast", stat.ast) | ||
.withTextValue("plan", stat.plan) | ||
.build(); | ||
} | ||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.