Skip to content

Commit

Permalink
Merge pull request #14 from singlestore-labs/bugfix/remove-intersect-…
Browse files Browse the repository at this point in the history
…all-tests

Remove intersect all tests
  • Loading branch information
apeng-singlestore authored Sep 4, 2024
2 parents aebe742 + 8e4ac82 commit c8c47d9
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 188 deletions.
85 changes: 0 additions & 85 deletions drizzle-orm/src/singlestore-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,48 +494,6 @@ export abstract class SingleStoreSelectQueryBuilderBase<
*/
intersect = this.createSetOperator('intersect', false);

/**
* Adds `intersect all` set operator to the query.
*
* Calling this method will retain only the rows that are present in both result sets including all duplicates.
*
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
*
* @example
*
* ```ts
* // Select all products and quantities that are ordered by both regular and VIP customers
* await db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders)
* .intersectAll(
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* // or
* import { intersectAll } from 'drizzle-orm/pg-core'
*
* await intersectAll(
* db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders),
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* ```
*/
intersectAll = this.createSetOperator('intersect', true);

/**
* Adds `except` set operator to the query.
*
Expand Down Expand Up @@ -1027,7 +985,6 @@ const getSingleStoreSetOperators = () => ({
union,
unionAll,
intersect,
intersectAll,
except,
exceptAll,
minus,
Expand Down Expand Up @@ -1114,48 +1071,6 @@ export const unionAll = createSetOperator('union', true);
*/
export const intersect = createSetOperator('intersect', false);

/**
* Adds `intersect all` set operator to the query.
*
* Calling this method will retain only the rows that are present in both result sets including all duplicates.
*
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
*
* @example
*
* ```ts
* // Select all products and quantities that are ordered by both regular and VIP customers
* import { intersectAll } from 'drizzle-orm/mysql-core'
*
* await intersectAll(
* db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders),
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* // or
* await db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders)
* .intersectAll(
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* ```
*/
export const intersectAll = createSetOperator('intersect', true);

/**
* Adds `except` set operator to the query.
*
Expand Down
31 changes: 0 additions & 31 deletions drizzle-orm/type-tests/singlestore/set-operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
except,
exceptAll,
intersect,
intersectAll,
type SingleStoreSetOperator,
union,
unionAll,
Expand Down Expand Up @@ -51,18 +50,6 @@ const intersectTest = await db

Expect<Equal<{ id: number; homeCity: number }[], typeof intersectTest>>;

const intersectAllTest = await db
.select({ id: users.id, homeCity: users.class })
.from(users)
.intersect(
db
.select({ id: users.id, homeCity: users.class })
.from(users)
.leftJoin(cities, eq(users.id, cities.id)),
);

Expect<Equal<{ id: number; homeCity: 'A' | 'C' }[], typeof intersectAllTest>>;

const exceptTest = await db
.select({ id: users.id, homeCity: users.homeCity })
.from(users)
Expand Down Expand Up @@ -120,24 +107,6 @@ const intersect2Test = await intersect(

Expect<Equal<{ id: number; name: string; population: number | null }[], typeof intersect2Test>>;

const intersectAll2Test = await intersectAll(
union(
db.select({
id: cities.id,
}).from(cities),
db.select({
id: cities.id,
})
.from(cities).where(sql``),
),
db.select({
id: cities.id,
})
.from(cities),
).orderBy(desc(cities.id)).limit(23);

Expect<Equal<{ id: number }[], typeof intersectAll2Test>>;

const except2Test = await except(
db.select({
userId: newYorkers.userId,
Expand Down
72 changes: 0 additions & 72 deletions integration-tests/tests/singlestore/singlestore-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
getViewConfig,
int,
intersect,
intersectAll,
json,
mediumint,
primaryKey,
Expand Down Expand Up @@ -2709,77 +2708,6 @@ export function tests(driver?: string) {
})()).rejects.toThrowError();
});

test('set operations (intersect all) from query builder', async (ctx) => {
const { db } = ctx.singlestore;

await setupSetOperationTest(db);

const sq = await db
.select({ id: citiesTable.id, name: citiesTable.name })
.from(citiesTable).limit(2).intersectAll(
db
.select({ id: citiesTable.id, name: citiesTable.name })
.from(citiesTable).limit(2),
).as('sq');

const result = await db.select().from(sq)

expect(result).toHaveLength(2);

expect(result).toEqual([
{ id: 1, name: 'New York' },
{ id: 2, name: 'London' },
]);

await expect((async () => {
db
.select({ id: citiesTable.id, name: citiesTable.name })
.from(citiesTable).limit(2).intersectAll(
db
.select({ name: citiesTable.name, id: citiesTable.id })
.from(citiesTable).limit(2),
).orderBy(asc(sql`id`));
})()).rejects.toThrowError();
});

test('set operations (intersect all) as function', async (ctx) => {
const { db } = ctx.singlestore;

await setupSetOperationTest(db);

const result = await intersectAll(
db
.select({ id: users2Table.id, name: users2Table.name })
.from(users2Table).where(eq(users2Table.id, 1)),
db
.select({ id: users2Table.id, name: users2Table.name })
.from(users2Table).where(eq(users2Table.id, 1)),
db
.select({ id: users2Table.id, name: users2Table.name })
.from(users2Table).where(eq(users2Table.id, 1)),
);

expect(result).toHaveLength(1);

expect(result).toEqual([
{ id: 1, name: 'John' },
]);

await expect((async () => {
intersectAll(
db
.select({ name: users2Table.name, id: users2Table.id })
.from(users2Table).where(eq(users2Table.id, 1)),
db
.select({ id: users2Table.id, name: users2Table.name })
.from(users2Table).where(eq(users2Table.id, 1)),
db
.select({ id: users2Table.id, name: users2Table.name })
.from(users2Table).where(eq(users2Table.id, 1)),
);
})()).rejects.toThrowError();
});

test('set operations (except) from query builder', async (ctx) => {
const { db } = ctx.singlestore;

Expand Down

0 comments on commit c8c47d9

Please sign in to comment.