Skip to content

Commit

Permalink
Add any existing ext::* scalar to a type's __casttype__ (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored Jul 11, 2023
1 parent 77f3c1d commit 1f4fdcf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
17 changes: 13 additions & 4 deletions integration-tests/stable/pgvector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ describe("pgvector", () => {
});

test("inferred return type + literal encoding", async () => {
const query = e.select(e.PgVectorTest, () => ({
test_embedding: true,
vector_literal: e.ext.pgvector.vector(Float32Array.from([1, 2, 3])),
}));
const query = e.select(e.PgVectorTest, ($) => {
const dist = e.ext.pgvector.cosine_distance(
$.test_embedding,
e.ext.pgvector.vector(Float32Array.from([1, 2, 3]))
);
return {
test_embedding: true,
vector_literal: e.ext.pgvector.vector(Float32Array.from([1, 2, 3])),
dist,
order_by: dist,
};
});

const result = await query.run(client);

Expand All @@ -41,6 +49,7 @@ describe("pgvector", () => {
{
test_embedding: Float32Array | null;
vector_literal: Float32Array;
dist: number | null;
}[]
>
>(true);
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/stable/setupTeardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function setupTests() {
}

async function cleanupData(client: Client) {
await client.execute(`reset schema to initial`);
await client.execute(`delete PgVectorTest`);
}

export async function teardownTests(client: Client) {
Expand Down
6 changes: 3 additions & 3 deletions packages/driver/src/reflection/queries/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export async function getTypes(
material_scalars := (
SELECT ScalarType
FILTER
(.name LIKE 'std::%' OR .name LIKE 'cal::%')
AND NOT .is_abstract
FILTER NOT .abstract
AND NOT EXISTS .enum_values
AND NOT EXISTS (SELECT .ancestors FILTER NOT .abstract)
)
SELECT Type {
Expand Down
10 changes: 8 additions & 2 deletions packages/generate/src/syntax/funcops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ export function $resolveOverload(
throw new Error(
`No function overload found for ${
funcName.includes("::")
? `'e.${funcName.split("::")[1]}()'`
? `'e.${funcName.split("::").join(".")}()'`
: `operator '${funcName}'`
} with args: ${args.map((arg) => `${arg}`).join(", ")}`
} with args: ${[...positionalArgs, ...Object.values(namedArgs ?? {})]
.filter(Boolean)
.map(
(arg) =>
`Element: ${arg!.__element__.__name__} (${arg!.__cardinality__})`
)
.join(", ")}`
);
}

Expand Down

0 comments on commit 1f4fdcf

Please sign in to comment.