-
Notifications
You must be signed in to change notification settings - Fork 426
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
chore: Add ShowByID filtering generation #3227
Conversation
…nowflake into sdk-generator-show-by-id
…eded Identifier value
Integration tests failure for 1599afb36a36122395af19213ab1a4562b220e90 |
pkg/sdk/poc/generator/templates/sub_templates/implementation_functions.tmpl
Outdated
Show resolved
Hide resolved
type ShowByIDFiltering struct { | ||
Kind string | ||
Args string | ||
IdentifierBased bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could use an enum instead? What if we have more showByIDs which have a different behavior? Such flag could be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, that would probably be a better approach than just a flag
…nowflake into sdk-generator-show-by-id
…nowflake into sdk-generator-show-by-id
return i.newNoSqlOperation(string(OperationKindShowByID)) | ||
func (i *Interface) ShowByIdOperation(filtering ...ShowByIDFilteringKind) *Interface { | ||
op := i.newNoSqlOperation(string(OperationKindShowByID)) | ||
op.ObjectInterface = i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operation.ObjectInterface
is being set here, because without it operation.ObjectInterface.ObjectIdentifierKind()
can't be used before executing the template. It results in nil pointer dereference, same as forInterface.NameLowerCased()
.
I wanted to use it before the template execution to invoke the filtering just by calling {{ .WithFiltering }}
in the template.
I'm open for discussion on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with assigning it in the constructor (newNoSqlOperation
in this case), it's not bad and imo could be added to other constructors that are Interface
methods
Integration tests failure for 46338317e73c3293098f0730143ed6f0e30a7d65 |
Integration tests failure for 04bc3ce16b052218b1b3ad833e6b4ca843c251a1 |
Integration tests failure for aaf81f1f9b74900a639cf369a122edf240e15904 |
Integration tests failure for 637082805361888801b0c3d59ad46a85cbbe634e |
return newShowByIDFiltering("In", "In", "%[1]v: id.%[1]vId()", &identifierKind) | ||
} | ||
|
||
func newShowByIDExtendedInFiltering(identifierKind string) ShowByIDFiltering { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have an enum for identifierKind
?
ShowByIDLimitFiltering: newShowByIDLimitFiltering, | ||
} | ||
|
||
func newShowByIDFiltering(name, kind, args string, identifierKind *string) ShowByIDFiltering { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using a variadic function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be done by formatting arguments in the create function (as discussed verbally). This way the identifier kind is removed from newShowByIDFiltering()
function and there is no need for variadic anymore.
pkg/sdk/poc/generator/templates/sub_templates/implementation_functions.tmpl
Outdated
Show resolved
Hide resolved
|
||
func (s *Operation) withFiltering(filtering ...ShowByIDFilteringKind) *Operation { | ||
for _, filteringKind := range filtering { | ||
switch filteringKind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with @sfc-gh-jmichalak to reject the usage of
map[ShowByIDFilteringKind]func(idPrefix) ShowByIDFiltering
and use a switch instead, so that there is no need to append more arguments to each function if new filtering is added
} | ||
|
||
func (s *showByIDApplicationFilter) WithFiltering() string { | ||
return fmt.Sprintf("With%s(%s)", s.Name, s.Args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showByIDApplicationFilter
uses different formatting than usual so this is an example of how to leverage the showByIDFilter
struct if other formatting is needed
{{ $impl }}, err := v.Show(ctx, NewShow{{ .ObjectInterface.NameSingular }}Request()) | ||
request := NewShow{{ .ObjectInterface.NameSingular }}Request() | ||
{{- range .ShowByIDFiltering }} | ||
{{- if not (eq .Name "NoFiltering") -}}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind the dot at the end here
checking for "NoFiltering" name allows for proper adding filtering options, one after another, and if NoFiltering
option is applied, the dot will not be present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier if the .ShowByIDFiltering
would have no items? Then the check wouldn't be necessary, plus you can have two items in the collection, one being NoFiltering
and the second SomeFilter
. What I mean is, there's nothing you can do now to prevent unwanted behavior. Maybe instead of NoFiltering
filtering option, we should rename the default function to emphasize the fact that no filtering is generated there (enum value is also good, but as mentioned, it could be used with other filters making it just a tag value).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I think having empty slice and removing this if
would be better.
return i | ||
} | ||
|
||
func (i *Interface) ShowByIdOperationWithFiltering(filter ShowByIDFilteringKind, filtering ...ShowByIDFilteringKind) *Interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New Operation forcing users to use filtering options (as discussed with @sfc-gh-asawicki)
ShowByIdOperation
without filtering should be removed later
Integration tests failure for 9cd65c3b480da5f80e0fae4fa39cfd921aeff55d |
Integration tests failure for 9d51aa9cb8cff056971ce5b4d6af669ec9cb76e7 |
return strings.Replace(i.IdentifierKind, "ObjectIdentifier", "", 1) | ||
// ObjectIdentifierKind returns the level of the object identifier (e.g. for DatabaseObjectIdentifier, it returns the prefix "Database") | ||
func (i *Interface) ObjectIdentifierPrefix() idPrefix { | ||
// return strings.Replace(i.IdentifierKind, "ObjectIdentifier", "", 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove if it doesn't serve any purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used to fill the "In" filtering with ObjectIdentifier prefixes based on the object identifier type e.g. DatabaseObjectIdentifier etc. So that the filtering is defined once, and is applicable for any ObejctIdentifier type.
op.ObjectInterface = i | ||
op.withFiltering(filtering...) | ||
op.withFiltering(append([]ShowByIDFilteringKind{filter}, filtering...)...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can do it a little bit shorter with (append(filtering, filter)...)
{{ $impl }}, err := v.Show(ctx, NewShow{{ .ObjectInterface.NameSingular }}Request()) | ||
request := NewShow{{ .ObjectInterface.NameSingular }}Request() | ||
{{- range .ShowByIDFiltering }} | ||
{{- if not (eq .Name "NoFiltering") -}}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier if the .ShowByIDFiltering
would have no items? Then the check wouldn't be necessary, plus you can have two items in the collection, one being NoFiltering
and the second SomeFilter
. What I mean is, there's nothing you can do now to prevent unwanted behavior. Maybe instead of NoFiltering
filtering option, we should rename the default function to emphasize the fact that no filtering is generated there (enum value is also good, but as mentioned, it could be used with other filters making it just a tag value).
🤖 I have created a release *beep* *boop* --- ## [0.100.0](v0.99.0...v0.100.0) (2024-12-12) ### 🎉 **What's new:** * Account v1 readiness ([#3236](#3236)) ([5df33a8](5df33a8)) * Account v1 readiness generated files ([#3242](#3242)) ([3df59dd](3df59dd)) * Account v1 readiness resource ([#3252](#3252)) ([8f5698d](8f5698d)) * Add a new account roles data source ([#3257](#3257)) ([b3d6b9e](b3d6b9e)) * Add account data source ([#3261](#3261)) ([6087fc9](6087fc9)) * Add all other functions and procedures implementations ([#3275](#3275)) ([7a6f68d](7a6f68d)) * Basic functions implementation ([#3269](#3269)) ([6d4a103](6d4a103)) * Basic procedures implementation ([#3271](#3271)) ([933335f](933335f)) * Docs, test, and missing parameter ([#3280](#3280)) ([10517f3](10517f3)) * Functions and procedures schemas and generated sources ([#3262](#3262)) ([9b70f87](9b70f87)) * Functions sdk update ([#3254](#3254)) ([fc1eace](fc1eace)) * Handle missing fields in function and procedure ([#3273](#3273)) ([53e7a0a](53e7a0a)) * Procedures schemas and generated sources ([#3263](#3263)) ([211ad46](211ad46)) * Procedures sdk update ([#3255](#3255)) ([682606a](682606a)) * Rework account parameter resource ([#3264](#3264)) ([15aa9c2](15aa9c2)) * Rework data types ([#3244](#3244)) ([05ada91](05ada91)) * support table data type ([#3274](#3274)) ([13401d5](13401d5)) * Tag association v1 readiness ([#3210](#3210)) ([04f6d54](04f6d54)) * Test imports and small fixes ([#3276](#3276)) ([a712195](a712195)) * Unsafe execute v1 readiness ([#3266](#3266)) ([c4f1e8f](c4f1e8f)) * Use new data types in sql builder for functions and procedures ([#3247](#3247)) ([69f677a](69f677a)) ### 🔧 **Misc** * Add ShowByID filtering generation ([#3227](#3227)) ([548ec42](548ec42)) * Adress small task-related todos ([#3243](#3243)) ([40de9ae](40de9ae)) * Apply masking ([#3234](#3234)) ([c209a8a](c209a8a)) * fix missing references in toOpts and changes with newlines ([#3240](#3240)) ([246547f](246547f)) * function tests ([#3279](#3279)) ([5af6efb](5af6efb)) * Improve config builders ([#3207](#3207)) ([425787c](425787c)) * Revert to proper env ([#3238](#3238)) ([5d4ed3b](5d4ed3b)) * Use service user for ci ([#3228](#3228)) ([2fb50d7](2fb50d7)) ### 🐛 **Bug fixes:** * Make blocked_roles_field optional in OAuth security integrations ([#3267](#3267)) ([7197b57](7197b57)) * Minor fixes ([#3231](#3231)) ([1863bf6](1863bf6)) * Minor fixes 2 ([#3230](#3230)) ([73b7e74](73b7e74)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: snowflake-release-please[bot] <105954990+snowflake-release-please[bot]@users.noreply.github.com>
<!-- Feel free to delete comments as you fill this in --> <!-- summary of changes --> ## Changes - removed generation of integration_tests file - added a print for the user to create the integration tests manually - changed the `ShowByIdOperation` name to `ShowByIdOperationNoFiltering` for no automatic generation of filtering options - adjusted the template for ShowByID filtering - removed `ShowByIDNoFiltering` option (replaced by `ShowByIdOperationNoFiltering`) - adjusted README of the SDK generator to the current state ## References <!-- issues documentation links, etc --> * #3227 * #3240
<!-- Feel free to delete comments as you fill this in --> <!-- summary of changes --> ## Changes - removed generation of integration_tests file - added a print for the user to create the integration tests manually - changed the `ShowByIdOperation` name to `ShowByIdOperationNoFiltering` for no automatic generation of filtering options - adjusted the template for ShowByID filtering - removed `ShowByIDNoFiltering` option (replaced by `ShowByIdOperationNoFiltering`) - adjusted README of the SDK generator to the current state ## References <!-- issues documentation links, etc --> * #3227 * #3240
Changes
implement_functions
templateOperation
struct with Filtering optionsTo generate filtering options, add filtering options in
ShowByIDOperation
:Test Plan
Generation for
Like
andExtendedIn
for SchemaObjectidentifier (Secrets):Generation for
Like
andIn
for SchemaObjectIdentifier (Streamlits):Generation for
Like
for AccountObjectIdentifier (Connections):Generation for
ApplicationName
for DatabaseObjectIdentifier (Application Roles):Notes
WithIn
andWithLike
are mostly used inShowByID()
Limit
andStartsWith
inShowByID()
application_roles
is the onlyDatabaseObejctIdentifier
with a_def
fileapplication_roles
does not implement any of the common filtering options e.g.OptionalLike()
orOptionalIn()
application_roles
implementWithApplicationName
filtering option that has been addedTODO
ShowByIdOperation()
toShowByIdOperationWithoutFiltering()
and remove NoFiltering Option