forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add support for adhoc columns (apache#1342)
* feat(core): add support for adhoc columns * simplify import * revert simplification due to codecov * fix filter column type * fix pivot v2 groupbys * remove redundant import * Add new type guards * move ColumnMeta type guards to chart-controls * add type guard tests * Fix typing and import errors * Fix saved expression type guard * Fix typing * Remove redundant import * Make Echarts and PivotTable handle AdhocColumns properly * Fix lint Co-authored-by: Kamil Gabryjelski <kamil.gabryjelski@gmail.com>
- Loading branch information
1 parent
4359ed0
commit e16a836
Showing
36 changed files
with
315 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../temporary_superset_ui/superset-ui/packages/superset-ui-chart-controls/test/types.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { AdhocColumn } from '@superset-ui/core'; | ||
import { isAdhocColumn, isColumnMeta, isSavedExpression } from '../src'; | ||
import { ColumnMeta } from '../lib'; | ||
|
||
const ADHOC_COLUMN: AdhocColumn = { | ||
hasCustomLabel: true, | ||
label: 'Adhoc column', | ||
sqlExpression: 'case when 1 = 1 then 1 else 2 end', | ||
}; | ||
const COLUMN_META: ColumnMeta = { | ||
column_name: 'my_col', | ||
}; | ||
const SAVED_EXPRESSION: ColumnMeta = { | ||
column_name: 'Saved expression', | ||
expression: 'case when 1 = 1 then 1 else 2 end', | ||
}; | ||
|
||
describe('isColumnMeta', () => { | ||
it('returns false for AdhocColumn', () => { | ||
expect(isColumnMeta(ADHOC_COLUMN)).toEqual(false); | ||
}); | ||
|
||
it('returns true for ColumnMeta', () => { | ||
expect(isColumnMeta(COLUMN_META)).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('isAdhocColumn', () => { | ||
it('returns true for AdhocColumn', () => { | ||
expect(isAdhocColumn(ADHOC_COLUMN)).toEqual(true); | ||
}); | ||
|
||
it('returns false for ColumnMeta', () => { | ||
expect(isAdhocColumn(COLUMN_META)).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('isSavedExpression', () => { | ||
it('returns false for AdhocColumn', () => { | ||
expect(isSavedExpression(ADHOC_COLUMN)).toEqual(false); | ||
}); | ||
|
||
it('returns false for ColumnMeta without expression', () => { | ||
expect(isSavedExpression(COLUMN_META)).toEqual(false); | ||
}); | ||
|
||
it('returns true for ColumnMeta with expression', () => { | ||
expect(isSavedExpression(SAVED_EXPRESSION)).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...d/temporary_superset_ui/superset-ui/packages/superset-ui-core/src/query/getColumnLabel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { isPhysicalColumn, QueryFormColumn } from './types'; | ||
|
||
export default function getColumnLabel(column: QueryFormColumn): string { | ||
if (isPhysicalColumn(column)) { | ||
return column; | ||
} | ||
if (column.label) { | ||
return column.label; | ||
} | ||
return column.sqlExpression; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...orary_superset_ui/superset-ui/packages/superset-ui-core/test/query/getColumnLabel.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { getColumnLabel } from '@superset-ui/core/src/query'; | ||
|
||
describe('getColumnLabel', () => { | ||
it('should handle physical column', () => { | ||
expect(getColumnLabel('gender')).toEqual('gender'); | ||
}); | ||
|
||
it('should handle adhoc columns with label', () => { | ||
expect( | ||
getColumnLabel({ | ||
sqlExpression: "case when 1 then 'a' else 'b' end", | ||
label: 'my col', | ||
}), | ||
).toEqual('my col'); | ||
}); | ||
|
||
it('should handle adhoc columns without label', () => { | ||
expect( | ||
getColumnLabel({ | ||
sqlExpression: "case when 1 then 'a' else 'b' end", | ||
}), | ||
).toEqual("case when 1 then 'a' else 'b' end"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.