feat(elasticsearch): add hit document view and field type detection

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-04 01:01:32 +08:00
1 parent 37dc74d9de
commit 0bdf232487
7 files changed
+205 -13

No files matched your search

@@ -25,6 +25,11 @@ describe("data grid type visual kind", () => {
["UUID", "identifier"],
["BYTEA", "binary"],
["SDO_GEOMETRY", "spatial"],
["keyword", "string"],
["unsigned_long", "integer"],
["scaled_float", "numeric"],
["date_nanos", "temporal"],
["nested", "structured"],
["inet", "unknown"],
])("maps %s to %s", (dataType, expected) => {
expect(resolveDataGridTypeVisualKind(dataType)).toBe(expected);
@@ -40,6 +45,10 @@ describe("data grid type visual kind", () => {
["rowversion", "sqlserver", "binary"],
["bit(8)", "postgres", "binary"],
["bit varying(8)", "postgres", "binary"],
["long", "elasticsearch", "integer"],
["long", "easysearch", "integer"],
["byte", "elasticsearch", "integer"],
["short", "elasticsearch", "integer"],
] as const)("maps %s for %s to %s", (dataType, databaseType, expected) => {
expect(resolveDataGridTypeVisualKind(dataType, databaseType)).toBe(expected);
});
@@ -49,6 +58,10 @@ describe("data grid type visual kind", () => {
expect(resolveDataGridTypeVisualKind("timestamp", "postgres")).toBe("temporal");
expect(resolveDataGridTypeVisualKind("bit")).toBe("boolean");
expect(resolveDataGridTypeVisualKind("bit", "sqlserver")).toBe("boolean");
expect(resolveDataGridTypeVisualKind("long")).toBe("string");
expect(resolveDataGridTypeVisualKind("long", "oracle")).toBe("string");
expect(resolveDataGridTypeVisualKind("byte")).toBe("unknown");
expect(resolveDataGridTypeVisualKind("short")).toBe("unknown");
});
});
@@ -1,4 +1,4 @@
import type { DatabaseType } from "@/types/database";
import { isElasticsearchCompatibleDatabaseType, type DatabaseType } from "@/types/database";
/**
* Resolve the data type to display in a data-grid column header.
@@ -148,6 +148,9 @@ const NUMERIC_COLUMN_TYPE_BASES = new Set([
"smallmoneyn",
"binary_float",
"binary_double",
// Elasticsearch numeric mapping types.
"half_float",
"scaled_float",
]);
export function isNumericColumnType(dataType: string | undefined): boolean {
@@ -194,8 +197,16 @@ const INTEGER_COLUMN_TYPE_BASES = new Set([
"uint128",
"uint256",
"year",
// Elasticsearch integer mapping types with unambiguous names.
"unsigned_long",
"token_count",
]);
// Elasticsearch integer mapping types whose names collide with other
// databases' non-integer types (Oracle LONG is a legacy text type, Informix
// BYTE is binary), so they only apply to Elasticsearch-compatible databases.
const ELASTICSEARCH_ONLY_INTEGER_COLUMN_TYPE_BASES = new Set(["byte", "short", "long"]);
const STRING_COLUMN_TYPE_BASES = new Set([
"varchar",
"varchar2",
@@ -221,11 +232,20 @@ const STRING_COLUMN_TYPE_BASES = new Set([
"character varying",
"national character",
"national character varying",
// Elasticsearch text-like mapping types.
"keyword",
"constant_keyword",
"wildcard",
"match_only_text",
"search_as_you_type",
"completion",
"ip",
"version",
]);
const BOOLEAN_COLUMN_TYPE_BASES = new Set(["bool", "boolean", "bit"]);
const TEMPORAL_COLUMN_TYPE_BASES = new Set(["date", "date32", "daten", "time", "time64", "timen", "timetz", "datetime", "datetime2", "datetime4", "datetime64", "datetimen", "datetimeoffset", "datetimeoffsetn", "smalldatetime", "timestamp", "timestampdty", "timestamptz", "interval"]);
const STRUCTURED_COLUMN_TYPE_BASES = new Set(["json", "jsonb", "jsonpath", "xml", "xmltype", "array", "map", "tuple", "struct", "row", "object", "document", "variant"]);
const TEMPORAL_COLUMN_TYPE_BASES = new Set(["date", "date_nanos", "date32", "daten", "time", "time64", "timen", "timetz", "datetime", "datetime2", "datetime4", "datetime64", "datetimen", "datetimeoffset", "datetimeoffsetn", "smalldatetime", "timestamp", "timestampdty", "timestamptz", "interval"]);
const STRUCTURED_COLUMN_TYPE_BASES = new Set(["json", "jsonb", "jsonpath", "xml", "xmltype", "array", "map", "tuple", "struct", "row", "object", "nested", "flattened", "document", "variant"]);
const IDENTIFIER_COLUMN_TYPE_BASES = new Set(["uuid", "uniqueidentifier", "rowid", "urowid"]);
const BINARY_COLUMN_TYPE_BASES = new Set(["bytea", "blob", "tinyblob", "mediumblob", "longblob", "binary", "varbinary", "image", "raw", "long raw", "bfile"]);
const SPATIAL_COLUMN_TYPE_BASES = new Set(["geometry", "geography", "sdo_geometry", "point", "linestring", "polygon", "multipoint", "multilinestring", "multipolygon", "geometrycollection"]);
@@ -280,6 +300,7 @@ export function resolveDataGridTypeVisualKind(dataType: string | undefined, data
if (array) return "structured";
if (databaseType === "sqlserver" && (base === "timestamp" || base === "rowversion")) return "binary";
if (databaseType === "postgres" && (base === "bit" || base === "bit varying")) return "binary";
if (isElasticsearchCompatibleDatabaseType(databaseType) && ELASTICSEARCH_ONLY_INTEGER_COLUMN_TYPE_BASES.has(base)) return "integer";
if (INTEGER_COLUMN_TYPE_BASES.has(base)) return "integer";
if (isNumericColumnType(dataType)) return "numeric";
if (BOOLEAN_COLUMN_TYPE_BASES.has(base)) return "boolean";