Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/cubejs-schema-compiler/src/adapter/BaseFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@
}
}

/**
* BaseFilter inherits from BaseDimension while Filter may be measure-based !!
*/
public override dateFieldType() {
if (this.measure) {
return this.measureDefinition().type; // There is no fieldType in measure, but it seems that it's enough

Check warning on line 98 in packages/cubejs-schema-compiler/src/adapter/BaseFilter.ts

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-schema-compiler/src/adapter/BaseFilter.ts#L98

Added line #L98 was not covered by tests
} else {
return this.dimensionDefinition().fieldType;
}
}

public cube() {
return this.query.cubeEvaluator.cubeFromPath(this.measure || this.dimension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ describe('SQL Generation', () => {
sql: \`\${revenue}\`,
type: 'sum',
group_by: [id]
},
min_created_at: {
type: 'time',
sql: 'MIN(created_at)'
}
},

Expand Down Expand Up @@ -1560,6 +1564,45 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
});
});

it('having filter (time measure)', async () => {
await compiler.compile();

const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
measures: [
'visitors.min_created_at'
],
dimensions: [
'visitors.source'
],
timeDimensions: [],
timezone: 'America/Los_Angeles',
filters: [{
dimension: 'visitors.min_created_at',
operator: 'inDateRange',
values: ['2017-01-01', '2018-01-01']
}],
order: [{
id: 'visitors.source'
}]
});

console.log(query.buildSqlAndParams());

return dbRunner.testQuery(query.buildSqlAndParams()).then(res => {
console.log(JSON.stringify(res));
expect(res).toEqual([
{
visitors__min_created_at: '2017-01-06T00:00:00.000Z',
visitors__source: 'google',
},
{
visitors__min_created_at: '2017-01-03T00:00:00.000Z',
visitors__source: 'some',
},
]);
});
});

it('having filter without measure', async () => {
await compiler.compile();

Expand Down
Loading