Skip to content
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

Simplify setting up Header objects #85

Merged
merged 3 commits into from Nov 29, 2023
Merged

Conversation

MasterOdin
Copy link
Contributor

PR modifies the headers.js file so that the header objects are generated from shared array of values, so that adding a new header is only done once, vs twice, to avoid duplication and potential mispellings and such. I also rewrote the overall object to be a regular object instead of a function with additional properties, as the latter struck me as a bit odd / unnecessary vs just using a regular object.

This is a prep PR for adding additional header values (e.g. language, role) that the adapter currently does not support.

Signed-off-by: Matthew Peveler <matt@popsql.com>
'Prepared-Statement',
];
const legacyPrefix = {
'PREPARE': 'Prepared-Statement',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only header to not follow the above simple rule, and I left it here to keep the objects overall backwards compatible, though the client itself uses the new PREPARED_STATEMENT key instead. I'm not sure anyone is relying on the header objects directly, so could potentially just delete this.

// with the key being the value uppercased and dashes replaced
// with underscores, e.g. `Max-Size` becomes
// `{ MAX_SIZE: 'X-Presto-Max-Size' }` on Headers object.
const commonPrefix = [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this commonSuffix? These parts become the suffix part of header fields (with Presto/Trino specific prefixes).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or commonFields makes sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with commonPrefix to indicate that these were fields that would be prefixed by the common X-${engine} string. However, I'm fine calling it commonSuffix instead. commonFields would also work, though I like using Suffix (or Prefix) as that gets mirrored into the legacySuffix variable and how that works.

Done in 1d0cc0c

lib/presto-client/headers.js Outdated Show resolved Hide resolved
lib/presto-client/headers.js Outdated Show resolved Hide resolved
@tagomoris
Copy link
Owner

👍

@tagomoris tagomoris merged commit 9adb821 into tagomoris:master Nov 29, 2023
3 checks passed
@MasterOdin MasterOdin deleted the chore-headers branch November 29, 2023 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants