Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: advanced sorting handler (#13788)
Liu Ji3af8e4f2655f
diff --git a/frontend/src/utils/v1/sql.ts b/frontend/src/utils/v1/sql.tsindex ba062ff60b..f4ddf70958 100644--- a/frontend/src/utils/v1/sql.ts+++ b/frontend/src/utils/v1/sql.ts@@ -1,20 +1,27 @@import dayjs from "dayjs";+import Long from "long";import { NullValue } from "@/types/proto/google/protobuf/struct";import { Engine } from "@/types/proto/v1/common";import { RowValue } from "@/types/proto/v1/sql_service";--export const extractSQLRowValue = (value: RowValue | undefined) => {+import { isNullOrUndefined } from "../util";++export const extractSQLRowValue = (+ value: RowValue | undefined+): { plain: any; raw: any } => {+ const fallback = (v: any) => {+ return { plain: v, raw: v };+ };if (typeof value === "undefined") {- return null;+ return fallback(null);}if (value.nullValue === NullValue.NULL_VALUE) {- return null;+ return fallback(null);}const plainObject = RowValue.toJSON(value) as Record<string, any>;const keys = Object.keys(plainObject);if (keys.length === 0) {- return undefined; // Will bi displayed as "UNSET"+ return fallback(undefined); // Will bi displayed as "UNSET"}if (keys.length > 1) {console.debug("mixed type in row value", value);@@ -30,12 +37,21 @@ export const extractSQLRowValue = (value: RowValue | undefined) => {}const binaryString = parts.join("").replace(/^0+/g, "");if (binaryString.length === 0) {- return "0";+ return {+ plain: "0",+ raw: byteArray,+ };}- return binaryString;+ return {+ plain: binaryString,+ raw: byteArray,+ };}const key = keys[0];- return plainObject[key];+ return {+ plain: plainObject[key],+ raw: (value as any)[key],+ };};export const wrapSQLIdentifier = (id: string, engine: Engine) => {@@ -157,8 +173,22 @@ export const compareQueryRowValues = (a: RowValue,b: RowValue): number => {- const valueA = extractSQLRowValue(a);- const valueB = extractSQLRowValue(b);+ const { plain: valueA, raw: rawA } = extractSQLRowValue(a);+ const { plain: valueB, raw: rawB } = extractSQLRowValue(b);++ // NULL or undefined values go behind+ if (isNullOrUndefined(valueA)) return 1;+ if (isNullOrUndefined(valueB)) return 0;++ if (Long.isLong(rawA) && Long.isLong(rawB)) {+ const cmp = rawA.compare(rawB);+ return cmp <= 0 ? 0 : 1;+ }++ if (typeof valueA === "number" && typeof valueB === "number") {+ return valueA - valueB;+ }+if (type === "INT" || type === "INTEGER") {const intA = toInt(valueA);const intB = toInt(valueB);diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vueindex 22b5ad472f..5ec3a1ac75 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue@@ -84,7 +84,7 @@ const classes = computed(() => {});const html = computed(() => {- const value = extractSQLRowValue(props.value);+ const value = extractSQLRowValue(props.value).plain;if (value === undefined) {return `<span class="text-gray-400 italic">UNSET</span>`;}diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vueindex 77e5f73d5f..9e82d05ff8 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue@@ -99,7 +99,7 @@ const detailValueString = computed(() => {.rows[row]?.getVisibleCells()[col]?.getValue<RowValue>();- return String(extractSQLRowValue(value));+ return String(extractSQLRowValue(value).plain);});const totalCount = computed(() => {diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vueindex 9caf3acd2f..91c52eebda 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue@@ -356,7 +356,7 @@ const data = computed(() => {if (search) {temp = data.filter((item) => {return item.values.some((col) => {- const value = extractSQLRowValue(col);+ const value = extractSQLRowValue(col).plain;if (isNullOrUndefined(value)) {return false;}@@ -502,7 +502,7 @@ const handleChangePage = (page: number) => {const explainFromSQLResultSetV1 = (resultSet: SQLResultSetV1 | undefined) => {if (!resultSet) return "";const lines = resultSet.results[0].rows.map((row) =>- row.values.map((value) => String(extractSQLRowValue(value)))+ row.values.map((value) => String(extractSQLRowValue(value).plain)));const explain = lines.map((line) => line[0]).join("\n");return explain;