feat(transwarp): add Inceptor data source with table operations
This commit is contained in:
1 parent
597b134d21
commit
6fdc338348
101 files changed
+2300
-66
No files matched your search
@@ -23,6 +23,7 @@ export function supportsObjectRename(databaseType: DatabaseType | undefined, obj
|
||||
return false;
|
||||
}
|
||||
if (databaseType === "sqlite" || databaseType === "rqlite" || databaseType === "turso" || databaseType === "cloudflare-d1" || databaseType === "duckdb") return objectType === "TABLE";
|
||||
if (databaseType === "transwarp") return objectType === "TABLE";
|
||||
if (databaseType === "mysql" || databaseType === "goldendb") return objectType === "TABLE" || objectType === "VIEW";
|
||||
if (postgresLikeRenameTypes.has(databaseType)) return objectType === "TABLE" || objectType === "VIEW" || objectType === "MATERIALIZED_VIEW";
|
||||
if (oracleLikeRenameTypes.has(databaseType)) return objectType === "TABLE" || objectType === "VIEW" || objectType === "MATERIALIZED_VIEW";
|
||||
|
||||
@@ -92,6 +92,12 @@ export function canDeleteExistingTdengineRows(databaseType: DatabaseType | undef
|
||||
|
||||
export function hiveTablePropertiesIndicateTransactional(result: { rows: readonly (readonly unknown[])[] }): boolean {
|
||||
return result.rows.some((row) => {
|
||||
if (row.length === 1)
|
||||
return (
|
||||
String(row[0] ?? "")
|
||||
.trim()
|
||||
.toLowerCase() === "true"
|
||||
);
|
||||
const name = String(row[0] ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { EditableStructureColumn, TranswarpCreateTableOptions } from "@/lib/table/tableStructureEditorSql";
|
||||
|
||||
export interface TablePhysicalOptionsDraft {
|
||||
partitionColumnIds: string[];
|
||||
distributionColumnIds: string[];
|
||||
bucketCount: string;
|
||||
storageFormat: string;
|
||||
transactional: boolean;
|
||||
}
|
||||
|
||||
export interface TablePhysicalOptionsConfig {
|
||||
partitionColumnsLabel: string;
|
||||
distributionColumnsLabel: string;
|
||||
bucketCountLabel: string;
|
||||
storageFormatLabel: string;
|
||||
transactionalLabel?: string;
|
||||
maxBuckets: number;
|
||||
storageFormats: readonly string[];
|
||||
}
|
||||
|
||||
export const INCEPTOR_PHYSICAL_OPTIONS: TablePhysicalOptionsConfig = {
|
||||
partitionColumnsLabel: "structureEditor.transwarpPartitionColumns",
|
||||
distributionColumnsLabel: "structureEditor.transwarpBucketColumns",
|
||||
bucketCountLabel: "structureEditor.transwarpBucketCount",
|
||||
storageFormatLabel: "structureEditor.transwarpStorageFormat",
|
||||
transactionalLabel: "structureEditor.transwarpTransactional",
|
||||
maxBuckets: 4096,
|
||||
storageFormats: ["ORC", "PARQUET", "TEXTFILE"],
|
||||
};
|
||||
|
||||
export function emptyTablePhysicalOptions(): TablePhysicalOptionsDraft {
|
||||
return { partitionColumnIds: [], distributionColumnIds: [], bucketCount: "", storageFormat: "", transactional: false };
|
||||
}
|
||||
|
||||
export function hasTablePhysicalOptions(draft: TablePhysicalOptionsDraft): boolean {
|
||||
return draft.partitionColumnIds.length > 0 || draft.distributionColumnIds.length > 0 || !!draft.bucketCount.trim() || !!draft.storageFormat || draft.transactional;
|
||||
}
|
||||
|
||||
export function pruneTablePhysicalOptions(draft: TablePhysicalOptionsDraft, availableColumnIds: ReadonlySet<string>): TablePhysicalOptionsDraft {
|
||||
const partitionColumnIds = draft.partitionColumnIds.filter((id) => availableColumnIds.has(id));
|
||||
const distributionColumnIds = draft.distributionColumnIds.filter((id) => availableColumnIds.has(id));
|
||||
if (partitionColumnIds.length === draft.partitionColumnIds.length && distributionColumnIds.length === draft.distributionColumnIds.length) return draft;
|
||||
return { ...draft, partitionColumnIds, distributionColumnIds };
|
||||
}
|
||||
|
||||
export function restoreTablePhysicalOptions(saved: { physicalOptions?: TablePhysicalOptionsDraft }): TablePhysicalOptionsDraft {
|
||||
if (!saved.physicalOptions) return emptyTablePhysicalOptions();
|
||||
return {
|
||||
partitionColumnIds: [...saved.physicalOptions.partitionColumnIds],
|
||||
distributionColumnIds: [...saved.physicalOptions.distributionColumnIds],
|
||||
bucketCount: saved.physicalOptions.bucketCount,
|
||||
storageFormat: saved.physicalOptions.storageFormat,
|
||||
transactional: saved.physicalOptions.transactional,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildInceptorCreateOptions(draft: TablePhysicalOptionsDraft, columns: readonly Pick<EditableStructureColumn, "id" | "name">[]): TranswarpCreateTableOptions {
|
||||
const names = (ids: readonly string[]) => ids.map((id) => columns.find((column) => column.id === id)?.name ?? id);
|
||||
const count = draft.bucketCount.trim();
|
||||
const parsedCount = Number(count);
|
||||
return {
|
||||
partitionColumns: names(draft.partitionColumnIds),
|
||||
bucketColumns: names(draft.distributionColumnIds),
|
||||
bucketCount: count ? (Number.isSafeInteger(parsedCount) && parsedCount > 0 && parsedCount <= 4096 ? parsedCount : 0) : undefined,
|
||||
storageFormat: draft.storageFormat || undefined,
|
||||
transactional: draft.transactional,
|
||||
};
|
||||
}
|
||||
@@ -109,6 +109,7 @@ export function quoteTableIdentifier(databaseType: DatabaseType | undefined, nam
|
||||
databaseType === "clickhouse" ||
|
||||
databaseType === "hive" ||
|
||||
databaseType === "argo" ||
|
||||
databaseType === "transwarp" ||
|
||||
databaseType === "kyuubi" ||
|
||||
databaseType === "impala" ||
|
||||
databaseType === "spark" ||
|
||||
@@ -152,6 +153,7 @@ function requiresIdentifierQuote(databaseType: DatabaseType | undefined, name: s
|
||||
case "clickhouse":
|
||||
case "hive":
|
||||
case "argo":
|
||||
case "transwarp":
|
||||
case "kyuubi":
|
||||
case "impala":
|
||||
case "spark":
|
||||
|
||||
@@ -268,6 +268,20 @@ const informixCapabilities = capabilities({
|
||||
rebuildIndex: true,
|
||||
});
|
||||
|
||||
// Inceptor accepts ADD COLUMNS and CHANGE. DROP COLUMN and index/constraint DDL
|
||||
// remain disabled until a safe server-supported form is verified.
|
||||
const transwarpCapabilities = capabilities({
|
||||
dialect: "mysql",
|
||||
createTable: true,
|
||||
addColumn: true,
|
||||
renameColumn: true,
|
||||
alterExistingColumn: true,
|
||||
alterType: true,
|
||||
alterNullability: true,
|
||||
alterDefault: true,
|
||||
comment: true,
|
||||
});
|
||||
|
||||
const accessCapabilities = capabilities({
|
||||
dialect: "h2",
|
||||
createTable: true,
|
||||
@@ -359,6 +373,7 @@ const capabilityByType: Partial<Record<DatabaseType, TableStructureCapabilities>
|
||||
access: accessCapabilities,
|
||||
clickhouse: clickhouseCapabilities,
|
||||
informix: informixCapabilities,
|
||||
transwarp: transwarpCapabilities,
|
||||
influxdb: influxdbCapabilities,
|
||||
manticoresearch: manticoreSearchCapabilities,
|
||||
};
|
||||
|
||||
@@ -90,6 +90,7 @@ export interface BuildTableStructureChangeSqlOptions {
|
||||
tableComment?: string;
|
||||
originalTableComment?: string;
|
||||
mysqlEngine?: string;
|
||||
transwarpCreate?: TranswarpCreateTableOptions;
|
||||
/** MySQL only: the table's current default collation. Columns whose collation merely
|
||||
* matches it inherit the table default, so the backend leaves their redundant
|
||||
* `CHARACTER SET`/`COLLATE` clauses out of the generated DDL. */
|
||||
@@ -103,6 +104,14 @@ export interface BuildTableStructureChangeSqlOptions {
|
||||
isGaussdbMMode?: boolean;
|
||||
}
|
||||
|
||||
export interface TranswarpCreateTableOptions {
|
||||
partitionColumns: string[];
|
||||
bucketColumns: string[];
|
||||
bucketCount?: number;
|
||||
storageFormat?: string;
|
||||
transactional: boolean;
|
||||
}
|
||||
|
||||
export interface TableStructureChangeSql {
|
||||
statements: string[];
|
||||
warnings: string[];
|
||||
|
||||
Reference in new issue
Block a user