Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: query response include rowsCount (#14687)
h3n4l21f73ed263c2
diff --git a/backend/api/v1/audit.go b/backend/api/v1/audit.goindex 859c77746c..0e4bd58392 100644--- a/backend/api/v1/audit.go+++ b/backend/api/v1/audit.go@@ -503,7 +503,7 @@ func redactQueryResponse(r *v1pb.QueryResponse) *v1pb.QueryResponse {ColumnNames: result.ColumnNames,ColumnTypeNames: result.ColumnTypeNames,Rows: nil, // Redacted- RowsCount: int64(len(result.Rows)),+ RowsCount: result.RowsCount,Masked: result.Masked,Sensitive: result.Sensitive,Error: result.Error,diff --git a/backend/plugin/db/bigquery/bigquery.go b/backend/plugin/db/bigquery/bigquery.goindex a644cc6b7c..0506f82fd0 100644--- a/backend/plugin/db/bigquery/bigquery.go+++ b/backend/plugin/db/bigquery/bigquery.go@@ -201,6 +201,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, q}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/clickhouse/query.go b/backend/plugin/db/clickhouse/query.goindex 4a5f033a98..212f514cc5 100644--- a/backend/plugin/db/clickhouse/query.go+++ b/backend/plugin/db/clickhouse/query.go@@ -88,6 +88,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/cockroachdb/cockroachdb.go b/backend/plugin/db/cockroachdb/cockroachdb.goindex ec64fca370..86ffc9c362 100644--- a/backend/plugin/db/cockroachdb/cockroachdb.go+++ b/backend/plugin/db/cockroachdb/cockroachdb.go@@ -769,6 +769,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/databricks/databricks.go b/backend/plugin/db/databricks/databricks.goindex c68343a54e..9298c30c72 100644--- a/backend/plugin/db/databricks/databricks.go+++ b/backend/plugin/db/databricks/databricks.go@@ -113,6 +113,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, _result.Rows = append(result.Rows, queryRow)}result.Latency = durationpb.New(time.Since(startTime))+ result.RowsCount = int64(len(result.Rows))results = append(results, result)}diff --git a/backend/plugin/db/dm/dm.go b/backend/plugin/db/dm/dm.goindex 3b607b3b83..56807bd691 100644--- a/backend/plugin/db/dm/dm.go+++ b/backend/plugin/db/dm/dm.go@@ -212,6 +212,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/dynamodb/dynamodb.go b/backend/plugin/db/dynamodb/dynamodb.goindex 098ad12ce6..0380f2a407 100644--- a/backend/plugin/db/dynamodb/dynamodb.go+++ b/backend/plugin/db/dynamodb/dynamodb.go@@ -160,6 +160,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, q}result.Latency = durationpb.New(time.Since(startTime))result.Statement = statement+ result.RowsCount = int64(len(result.Rows))results = append(results, result)if stop {breakdiff --git a/backend/plugin/db/elasticsearch/elasticsearch.go b/backend/plugin/db/elasticsearch/elasticsearch.goindex e962529e5c..67dab98e28 100644--- a/backend/plugin/db/elasticsearch/elasticsearch.go+++ b/backend/plugin/db/elasticsearch/elasticsearch.go@@ -218,6 +218,7 @@ func (d *Driver) QueryConn(_ context.Context, _ *sql.Conn, statement string, _ d}result.Rows = append(result.Rows, &row)result.Latency = durationpb.New(time.Since(startTime))+ result.RowsCount = int64(len(result.Rows))result.Statement = fmt.Sprintf("%s %s\n%s", s.method, s.route, s.queryBody)// TODO(d): handle max size.results = append(results, &result)diff --git a/backend/plugin/db/hive/hive.go b/backend/plugin/db/hive/hive.goindex 83d816956a..e88ae2a5c3 100644--- a/backend/plugin/db/hive/hive.go+++ b/backend/plugin/db/hive/hive.go@@ -229,6 +229,7 @@ func runSingleStatement(ctx context.Context, conn *gohive.Connection, statement}}result.Latency = durationpb.New(time.Since(startTime))+ result.RowsCount = int64(len(result.Rows))return result, nil}diff --git a/backend/plugin/db/mongodb/mongodb.go b/backend/plugin/db/mongodb/mongodb.goindex cbcd677d29..00f60ae32f 100644--- a/backend/plugin/db/mongodb/mongodb.go+++ b/backend/plugin/db/mongodb/mongodb.go@@ -387,6 +387,7 @@ func (driver *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement stri}},Latency: durationpb.New(time.Since(startTime)),Statement: statement,+ RowsCount: 0, /* unknown */}}, nil}diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.goindex e5477d0d01..17da6a6a70 100644--- a/backend/plugin/db/mysql/mysql.go+++ b/backend/plugin/db/mysql/mysql.go@@ -470,6 +470,7 @@ func (d *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement string}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/obo/obo.go b/backend/plugin/db/obo/obo.goindex 11a15b7ad8..fedb5ff2dd 100644--- a/backend/plugin/db/obo/obo.go+++ b/backend/plugin/db/obo/obo.go@@ -208,6 +208,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/oracle/oracle.go b/backend/plugin/db/oracle/oracle.goindex 4fb1d9d6b1..ff97f65d16 100644--- a/backend/plugin/db/oracle/oracle.go+++ b/backend/plugin/db/oracle/oracle.go@@ -277,6 +277,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/pg/pg.go b/backend/plugin/db/pg/pg.goindex 6849c6a473..91f5c5d121 100644--- a/backend/plugin/db/pg/pg.go+++ b/backend/plugin/db/pg/pg.go@@ -727,6 +727,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/redis/redis.go b/backend/plugin/db/redis/redis.goindex 6e17b186fa..bd9fdf0835 100644--- a/backend/plugin/db/redis/redis.go+++ b/backend/plugin/db/redis/redis.go@@ -275,6 +275,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, qfor i, cmd := range cmds {setQueryResultRows(results[i], cmd, d.maximumSQLResultSize)results[i].Latency = durationpb.New(time.Since(startTime))+ results[i].RowsCount = int64(len(results[i].Rows))}case v1pb.QueryOption_ALL_NODES:@@ -318,6 +319,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, qfor i, cmd := range cmds {setQueryResultRows(results[i], cmd, d.maximumSQLResultSize)results[i].Latency = durationpb.New(time.Since(startTime))+ results[i].RowsCount = int64(len(results[i].Rows))}}default:diff --git a/backend/plugin/db/redshift/redshift.go b/backend/plugin/db/redshift/redshift.goindex c3865e2cd1..e4015d4acf 100644--- a/backend/plugin/db/redshift/redshift.go+++ b/backend/plugin/db/redshift/redshift.go@@ -381,6 +381,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/risingwave/risingwave.go b/backend/plugin/db/risingwave/risingwave.goindex cb8a0da313..14e492f3bd 100644--- a/backend/plugin/db/risingwave/risingwave.go+++ b/backend/plugin/db/risingwave/risingwave.go@@ -402,6 +402,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/snowflake/snowflake.go b/backend/plugin/db/snowflake/snowflake.goindex 2bfb4111e5..8750af10a3 100644--- a/backend/plugin/db/snowflake/snowflake.go+++ b/backend/plugin/db/snowflake/snowflake.go@@ -332,6 +332,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/spanner/spanner.go b/backend/plugin/db/spanner/spanner.goindex a803cc2c6b..a19ba79ba9 100644--- a/backend/plugin/db/spanner/spanner.go+++ b/backend/plugin/db/spanner/spanner.go@@ -312,6 +312,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, q}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/sqlite/sqlite.go b/backend/plugin/db/sqlite/sqlite.goindex 08702e0095..a2e9ab539d 100644--- a/backend/plugin/db/sqlite/sqlite.go+++ b/backend/plugin/db/sqlite/sqlite.go@@ -173,5 +173,6 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}result.Latency = durationpb.New(time.Since(startTime))result.Statement = statement+ result.RowsCount = int64(len(result.Rows))return []*v1pb.QueryResult{result}, nil}diff --git a/backend/plugin/db/starrocks/starrocks.go b/backend/plugin/db/starrocks/starrocks.goindex 377b004977..b70e28b18d 100644--- a/backend/plugin/db/starrocks/starrocks.go+++ b/backend/plugin/db/starrocks/starrocks.go@@ -283,6 +283,7 @@ func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement s}queryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/tidb/tidb.go b/backend/plugin/db/tidb/tidb.goindex 0fe493f27e..b241a437d9 100644--- a/backend/plugin/db/tidb/tidb.go+++ b/backend/plugin/db/tidb/tidb.go@@ -384,6 +384,7 @@ func (d *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement stringqueryResult.Statement = statementqueryResult.Latency = durationpb.New(time.Since(startTime))+ queryResult.RowsCount = int64(len(queryResult.Rows))results = append(results, queryResult)if stop {breakdiff --git a/backend/plugin/db/util/driverutil.go b/backend/plugin/db/util/driverutil.goindex 7c5002db71..5d48f15461 100644--- a/backend/plugin/db/util/driverutil.go+++ b/backend/plugin/db/util/driverutil.go@@ -94,7 +94,7 @@ func RowsToQueryResult(rows *sql.Rows, valueMaker func(string, *sql.ColumnType)if err := rows.Err(); err != nil {return nil, err}-+ result.RowsCount = int64(len(result.Rows))return result, nil}diff --git a/backend/tests/sensitive_data_test.go b/backend/tests/sensitive_data_test.goindex 7c4ed95a80..6bffe167f9 100644--- a/backend/tests/sensitive_data_test.go+++ b/backend/tests/sensitive_data_test.go@@ -48,6 +48,7 @@ var (},},Statement: "SELECT * FROM tech_book",+ RowsCount: 3,}originData = &v1pb.QueryResult{ColumnNames: []string{"id", "name", "author"},@@ -76,6 +77,7 @@ var (},},Statement: "SELECT * FROM tech_book",+ RowsCount: 3,})diff --git a/backend/tests/sql_editor_test.go b/backend/tests/sql_editor_test.goindex e58e3f569d..1be708fd73 100644--- a/backend/tests/sql_editor_test.go+++ b/backend/tests/sql_editor_test.go@@ -44,6 +44,7 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},Statement: "INSERT INTO tbl VALUES(1);",+ RowsCount: 1,},},},@@ -64,6 +65,7 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},Statement: "INSERT INTO tbl VALUES(1);",+ RowsCount: 1,},{ColumnNames: []string{"Affected Rows"},@@ -76,6 +78,7 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},Statement: " DELETE FROM tbl WHERE id = 1;",+ RowsCount: 1,},},},@@ -96,6 +99,7 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},Statement: "INSERT INTO tbl VALUES(1),(2);",+ RowsCount: 1,},},},@@ -116,6 +120,7 @@ func TestAdminQueryAffectedRows(t *testing.T) {},},Statement: "ALTER TABLE tbl ADD COLUMN name VARCHAR(255);",+ RowsCount: 1,},},},diff --git a/backend/tests/sql_export_test.go b/backend/tests/sql_export_test.goindex 014502471b..36092c0e18 100644--- a/backend/tests/sql_export_test.go+++ b/backend/tests/sql_export_test.go@@ -56,6 +56,7 @@ func TestSQLExport(t *testing.T) {},},Statement: "INSERT INTO Test1.tbl (id, name, gender, height) VALUES(1, 'Alice', B'0', B'01111111');",+ RowsCount: 1,},},resetResult: []*v1pb.QueryResult{@@ -69,6 +70,7 @@ func TestSQLExport(t *testing.T) {},},},+ RowsCount: 1,},},},@@ -91,6 +93,7 @@ func TestSQLExport(t *testing.T) {},},},+ RowsCount: 1,},},resetResult: []*v1pb.QueryResult{@@ -104,6 +107,7 @@ func TestSQLExport(t *testing.T) {},},},+ RowsCount: 1,},},},diff --git a/backend/tests/sql_review_test.go b/backend/tests/sql_review_test.goindex 3f17667b8c..1e0e0fa702 100644--- a/backend/tests/sql_review_test.go+++ b/backend/tests/sql_review_test.go@@ -250,6 +250,7 @@ func TestSQLReviewForMySQL(t *testing.T) {},},Statement: "SELECT count(*) FROM test WHERE 1=1;",+ RowsCount: 1,})