Skip to content

Commit f351291

Browse files
authored
Merge pull request #519 from devforth/feature/AdminForth/1353/qdrant-field-discovery-doesn't
fix: correct discover fields for the qdrant, if there is an empty col…
2 parents 29d7eec + 26ea14e commit f351291

File tree

1 file changed

+15
-43
lines changed

1 file changed

+15
-43
lines changed

adminforth/dataConnectors/qdrant.ts

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -95,50 +95,22 @@ class QdrantConnector extends AdminForthBaseConnector implements IAdminForthData
9595
return (collections.collections ?? []).map((collection: { name: string }) => collection.name);
9696
}
9797

98-
// get all columns in a collection
99-
async getAllColumnsInTable(tableName: string): Promise<Array<{ name: string; type?: string; isPrimaryKey?: boolean; sampleValue?: any; }>> {
100-
const response = await this.client.scroll(tableName, {
101-
limit: 1,
102-
with_payload: true,
103-
with_vector: true,
104-
});
105-
const point = ((response.points ?? [])[0] ?? {}) as QdrantPoint;
106-
const payload = point.payload ?? {};
107-
const vector = point.vector ?? null;
108-
109-
const fields: Array<{ name: string; type?: string; isPrimaryKey?: boolean; sampleValue?: any; }> = [
110-
{ name: 'id', type: AdminForthDataTypes.STRING, isPrimaryKey: true, sampleValue: point.id ?? null },
111-
{ name: 'payload', type: AdminForthDataTypes.JSON, sampleValue: payload },
112-
];
113-
114-
if (vector !== undefined) {
115-
fields.push({ name: 'vector', type: AdminForthDataTypes.JSON, sampleValue: vector });
116-
}
117-
118-
for (const [name, sampleValue] of Object.entries(payload)) {
119-
fields.push({
120-
name,
121-
type: this.detectColumnType(sampleValue),
122-
sampleValue,
123-
});
124-
}
125-
126-
return fields;
127-
}
98+
// discover fields
99+
async discoverFields(resource) {
100+
return resource.columns.filter((col) => !col.virtual).reduce((acc, col) => {
101+
if (!col.type) {
102+
throw new Error(`Type is not defined for column ${col.name} in resource ${resource.table}`);
103+
}
128104

129-
// discover fields
130-
async discoverFields(resource: AdminForthResource, _config: AdminForthConfig): Promise<{ [key: string]: AdminForthResourceColumn; }> {
131-
const columns = await this.getAllColumnsInTable(this.getCollectionName(resource));
132-
return columns.reduce((acc, column) => {
133-
acc[column.name] = {
134-
name: column.name,
135-
type: (column.type as AdminForthDataTypes) ?? AdminForthDataTypes.STRING,
136-
primaryKey: column.isPrimaryKey ?? false,
137-
required: column.name === 'id' ? { create: true, edit: true } : undefined,
138-
_underlineType: column.type ?? 'unknown',
139-
} as AdminForthResourceColumn;
140-
return acc;
141-
}, {} as { [key: string]: AdminForthResourceColumn; });
105+
acc[col.name] = {
106+
name: col.name,
107+
type: col.type,
108+
primaryKey: col.primaryKey,
109+
virtual: col.virtual,
110+
_underlineType: col._underlineType,
111+
};
112+
return acc;
113+
}, {});
142114
}
143115

144116
// get field value

0 commit comments

Comments
 (0)