diff --git a/apps/nestjs-backend/src/db-provider/filter-query/postgres/cell-value-filter/single-value/string-cell-value-filter.adapter.ts b/apps/nestjs-backend/src/db-provider/filter-query/postgres/cell-value-filter/single-value/string-cell-value-filter.adapter.ts index 04553dc4e..0e6ddd578 100644 --- a/apps/nestjs-backend/src/db-provider/filter-query/postgres/cell-value-filter/single-value/string-cell-value-filter.adapter.ts +++ b/apps/nestjs-backend/src/db-provider/filter-query/postgres/cell-value-filter/single-value/string-cell-value-filter.adapter.ts @@ -1,4 +1,4 @@ -import type { IFilterOperator, ILiteralValue } from '@teable/core'; +import type { IFilterOperator, IFilterValue, ILiteralValue } from '@teable/core'; import type { Knex } from 'knex'; import { CellValueFilterPostgres } from '../cell-value-filter.postgres'; @@ -34,4 +34,26 @@ export class StringCellValueFilterAdapter extends CellValueFilterPostgres { ): Knex.QueryBuilder { return super.doesNotContainOperatorHandler(builderClient, operator, value); } + + isEmptyOperatorHandler( + builderClient: Knex.QueryBuilder, + _operator: IFilterOperator, + _value: IFilterValue + ): Knex.QueryBuilder { + builderClient.where((builder) => { + builder.whereNull(this.tableColumnRef).orWhere(this.tableColumnRef, ''); + }); + return builderClient; + } + + isNotEmptyOperatorHandler( + builderClient: Knex.QueryBuilder, + _operator: IFilterOperator, + _value: IFilterValue + ): Knex.QueryBuilder { + builderClient.where((builder) => { + builder.whereNotNull(this.tableColumnRef).andWhereNot(this.tableColumnRef, ''); + }); + return builderClient; + } } diff --git a/apps/nestjs-backend/test/data-helpers/20x.ts b/apps/nestjs-backend/test/data-helpers/20x.ts index 1c6518e51..450e3266b 100644 --- a/apps/nestjs-backend/test/data-helpers/20x.ts +++ b/apps/nestjs-backend/test/data-helpers/20x.ts @@ -288,7 +288,7 @@ export const x_20 = { }, { fields: { - [textField.name]: 'Text Field 20', + [textField.name]: '', [numberField.name]: 20, [checkboxField.name]: true, [dateField.name]: new DateUtil('Asia/Singapore', true).date().toISOString(), diff --git a/apps/nestjs-backend/test/data-helpers/caces/aggregation-query/text-field.ts b/apps/nestjs-backend/test/data-helpers/caces/aggregation-query/text-field.ts index 323bccdcd..d3020a8a1 100644 --- a/apps/nestjs-backend/test/data-helpers/caces/aggregation-query/text-field.ts +++ b/apps/nestjs-backend/test/data-helpers/caces/aggregation-query/text-field.ts @@ -5,42 +5,42 @@ export const TEXT_FIELD_CASES = [ fieldIndex: 0, aggFunc: StatisticsFunc.Count, expectValue: 23, - expectGroupedCount: 22, + expectGroupedCount: 21, }, { fieldIndex: 0, aggFunc: StatisticsFunc.Empty, - expectValue: 1, - expectGroupedCount: 22, + expectValue: 2, + expectGroupedCount: 21, }, { fieldIndex: 0, aggFunc: StatisticsFunc.Filled, - expectValue: 22, - expectGroupedCount: 22, + expectValue: 21, + expectGroupedCount: 21, }, { fieldIndex: 0, aggFunc: StatisticsFunc.Unique, - expectValue: 21, - expectGroupedCount: 22, + expectValue: 20, + expectGroupedCount: 21, }, { fieldIndex: 0, aggFunc: StatisticsFunc.PercentEmpty, - expectValue: 4.347826, - expectGroupedCount: 22, + expectValue: 8.695652, + expectGroupedCount: 21, }, { fieldIndex: 0, aggFunc: StatisticsFunc.PercentFilled, - expectValue: 95.652173, - expectGroupedCount: 22, + expectValue: 91.304347, + expectGroupedCount: 21, }, { fieldIndex: 0, aggFunc: StatisticsFunc.PercentUnique, - expectValue: 91.304347, - expectGroupedCount: 22, + expectValue: 86.956521, + expectGroupedCount: 21, }, ]; diff --git a/apps/nestjs-backend/test/data-helpers/caces/record-filter-query/text-field.ts b/apps/nestjs-backend/test/data-helpers/caces/record-filter-query/text-field.ts index 49e4b9fcc..79e4d5493 100644 --- a/apps/nestjs-backend/test/data-helpers/caces/record-filter-query/text-field.ts +++ b/apps/nestjs-backend/test/data-helpers/caces/record-filter-query/text-field.ts @@ -5,14 +5,14 @@ export const TEXT_FIELD_CASES = [ fieldIndex: 0, operator: isEmpty.value, queryValue: null, - expectResultLength: 1, + expectResultLength: 2, expectMoreResults: false, }, { fieldIndex: 0, operator: isNotEmpty.value, queryValue: null, - expectResultLength: 22, + expectResultLength: 21, expectMoreResults: false, }, { @@ -33,14 +33,14 @@ export const TEXT_FIELD_CASES = [ fieldIndex: 0, operator: contains.value, queryValue: 'Text', - expectResultLength: 22, + expectResultLength: 21, expectMoreResults: true, }, { fieldIndex: 0, operator: doesNotContain.value, queryValue: 'Text', - expectResultLength: 1, + expectResultLength: 2, expectMoreResults: false, }, ];