-
Notifications
You must be signed in to change notification settings - Fork 95
Add string_agg
function, partition_by
and order_by
for analytic functions, and partition_by
and limit
for string_agg
#1568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
0209bd0
Add string_agg function
79698d0
WIP
b7bb290
WIP with syntax for order by and limit
945beec
WIP
6159639
Remove old stuff
b1774aa
Merge branch 'main' into string_agg
f0f2f57
Remove another old thing
2bea50e
Add/improve tests
e7b9bb8
Revert "Remove old stuff"
0a9fd14
Revert "Remove another old thing"
276c818
WIP -- actually go back to field props method of spcifying order by a…
0f15979
WIP Partition by
33b44cc
Allow order_by to be used for analytic functions, and add a real test…
9e99fb1
(experimental) allow dialects to have different values of supportsLim…
80ff15f
Partition by does not allow expressions actually, only output field n…
3077087
Remove test for filter shortcut (it is gone)
17a4009
Add string_agg_distinct
86e5efa
Fix issue with orderBy showing up as undefined: OVER ( undefined )
ab46357
Add errors for misusing field props, and add experiment ids
86af91c
Fix non-ordered string_agg test to allow either ordering
fac9810
Same thing for string_agg_distinct
634374a
Allow multuiple partition_by, order_by, and where statements in field…
9eb958e
Move some files around
5a66be0
Remove outdated methods
97300d2
Add partition by to grammar
84b2ed7
Remove old code
3c0206f
Lint fix
708ac4c
Fix analytic ordering to allow aggregate or output field, fix aggrega…
e292c31
Require comma for partition by
bf12634
Use `malloyResultMatches` for tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files | ||
* (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, | ||
* and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import {Fragment} from '../../model'; | ||
import { | ||
overload, | ||
minAggregate, | ||
maxScalar, | ||
sql, | ||
DialectFunctionOverloadDef, | ||
makeParam, | ||
literal, | ||
} from './util'; | ||
|
||
export function fnStringAgg(): DialectFunctionOverloadDef[] { | ||
const value = makeParam('value', maxScalar('string')); | ||
const separator = makeParam('separator', literal(maxScalar('string'))); | ||
const orderBy: Fragment = {type: 'aggregate_order_by'}; | ||
return [ | ||
overload( | ||
minAggregate('string'), | ||
[value.param], | ||
sql`STRING_AGG(${value.arg}${orderBy})`, | ||
{supportsOrderBy: true} | ||
), | ||
overload( | ||
minAggregate('string'), | ||
[value.param, separator.param], | ||
sql`STRING_AGG(${value.arg}, ${separator.arg}${orderBy})`, | ||
{supportsOrderBy: true} | ||
), | ||
]; | ||
} | ||
|
||
export function fnStringAggDistinct(): DialectFunctionOverloadDef[] { | ||
const value = makeParam('value', maxScalar('string')); | ||
const separator = makeParam('separator', literal(maxScalar('string'))); | ||
const orderBy: Fragment = {type: 'aggregate_order_by'}; | ||
return [ | ||
overload( | ||
minAggregate('string'), | ||
[value.param], | ||
sql`STRING_AGG(DISTINCT ${value.arg}${orderBy})`, | ||
{isSymmetric: true, supportsOrderBy: true} | ||
), | ||
overload( | ||
minAggregate('string'), | ||
[value.param, separator.param], | ||
sql`STRING_AGG(DISTINCT ${value.arg}, ${separator.arg}${orderBy})`, | ||
{isSymmetric: true, supportsOrderBy: true} | ||
), | ||
]; | ||
} |
This file contains hidden or 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 hidden or 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
73 changes: 73 additions & 0 deletions
73
packages/malloy/src/dialect/postgres/functions/string_agg.ts
This file contains hidden or 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,73 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files | ||
* (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, | ||
* and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import {Fragment} from '../../../model'; | ||
import { | ||
overload, | ||
minAggregate, | ||
maxScalar, | ||
sql, | ||
DialectFunctionOverloadDef, | ||
makeParam, | ||
literal, | ||
} from '../../functions/util'; | ||
|
||
export function fnStringAgg(): DialectFunctionOverloadDef[] { | ||
const value = makeParam('value', maxScalar('string')); | ||
const separator = makeParam('separator', literal(maxScalar('string'))); | ||
const orderBy: Fragment = {type: 'aggregate_order_by'}; | ||
return [ | ||
christopherswenson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
overload( | ||
minAggregate('string'), | ||
[value.param], | ||
sql`STRING_AGG(${value.arg}, ','${orderBy})`, | ||
{supportsOrderBy: true} | ||
), | ||
overload( | ||
minAggregate('string'), | ||
[value.param, separator.param], | ||
sql`STRING_AGG(${value.arg}, ${separator.arg}${orderBy})`, | ||
{supportsOrderBy: true} | ||
), | ||
]; | ||
} | ||
|
||
export function fnStringAggDistinct(): DialectFunctionOverloadDef[] { | ||
const value = makeParam('value', maxScalar('string')); | ||
const separator = makeParam('separator', literal(maxScalar('string'))); | ||
const orderBy: Fragment = {type: 'aggregate_order_by'}; | ||
return [ | ||
overload( | ||
minAggregate('string'), | ||
[value.param], | ||
sql`STRING_AGG(DISTINCT ${value.arg}, ','${orderBy})`, | ||
{isSymmetric: true, supportsOrderBy: true} | ||
), | ||
overload( | ||
minAggregate('string'), | ||
[value.param, separator.param], | ||
sql`STRING_AGG(DISTINCT ${value.arg}, ${separator.arg}${orderBy})`, | ||
{isSymmetric: true, supportsOrderBy: true} | ||
), | ||
]; | ||
} |
This file contains hidden or 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
75 changes: 75 additions & 0 deletions
75
packages/malloy/src/dialect/standardsql/functions/string_agg.ts
This file contains hidden or 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,75 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files | ||
* (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, | ||
* and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import {Fragment} from '../../../model'; | ||
import { | ||
overload, | ||
minAggregate, | ||
maxScalar, | ||
sql, | ||
DialectFunctionOverloadDef, | ||
makeParam, | ||
literal, | ||
} from '../../functions/util'; | ||
|
||
export function fnStringAgg(): DialectFunctionOverloadDef[] { | ||
const value = makeParam('value', maxScalar('string')); | ||
const separator = makeParam('separator', literal(maxScalar('string'))); | ||
const orderBy: Fragment = {type: 'aggregate_order_by'}; | ||
const limit: Fragment = {type: 'aggregate_limit'}; | ||
return [ | ||
overload( | ||
minAggregate('string'), | ||
[value.param], | ||
sql`STRING_AGG(${value.arg}${orderBy}${limit})`, | ||
{supportsOrderBy: true, supportsLimit: true} | ||
), | ||
overload( | ||
minAggregate('string'), | ||
[value.param, separator.param], | ||
sql`STRING_AGG(${value.arg}, ${separator.arg}${orderBy}${limit})`, | ||
{supportsOrderBy: true, supportsLimit: true} | ||
), | ||
]; | ||
} | ||
|
||
export function fnStringAggDistinct(): DialectFunctionOverloadDef[] { | ||
const value = makeParam('value', maxScalar('string')); | ||
const separator = makeParam('separator', literal(maxScalar('string'))); | ||
const orderBy: Fragment = {type: 'aggregate_order_by'}; | ||
const limit: Fragment = {type: 'aggregate_limit'}; | ||
return [ | ||
overload( | ||
minAggregate('string'), | ||
[value.param], | ||
sql`STRING_AGG(DISTINCT ${value.arg}${orderBy}${limit})`, | ||
{isSymmetric: true, supportsOrderBy: true, supportsLimit: true} | ||
), | ||
overload( | ||
minAggregate('string'), | ||
[value.param, separator.param], | ||
sql`STRING_AGG(DISTINCT ${value.arg}, ${separator.arg}${orderBy}${limit})`, | ||
{isSymmetric: true, supportsOrderBy: true, supportsLimit: true} | ||
), | ||
]; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.