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

feat: export queryFieldInfo and jsType #625

Merged
merged 8 commits into from
Dec 13, 2024

Conversation

kwonoh
Copy link
Contributor

@kwonoh kwonoh commented Dec 4, 2024

export two utils functions queryFieldInfo and jsType

@jheer
Copy link
Member

jheer commented Dec 4, 2024

Thanks @kwonoh. This looks like a reasonable and straightforward modification. Can you share a bit more about why you'd like to have these methods exported? (It helps us to keep track of various use cases!)

@kwonoh
Copy link
Contributor Author

kwonoh commented Dec 4, 2024

Hi @jheer,

  • queryFieldInfo: I will use this for a catalog feature in my application to provide information about multiple tables (e.g., get what tables are available via information_schema.tables and use queryFieldInfo to get the column information of each table)
  • jsType: I plan to use this to determine expected JS types returned from some dynamically built queries. Also, I might use this function for the catalog feature purpose as well (e.g., use against data_type column of information_schema.columns).

@jheer jheer self-requested a review December 4, 2024 19:07
Copy link
Member

@jheer jheer left a comment

Choose a reason for hiding this comment

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

Overall looks good. If we're going to expose the queryFieldInfo method, we should also add jsdoc comments and types before merging.

@kwonoh
Copy link
Contributor Author

kwonoh commented Dec 4, 2024

Addressing test failures

@kwonoh
Copy link
Contributor Author

kwonoh commented Dec 5, 2024

@jheer I have added the jsdoc and type definitions. Now, it passes the tests, but please review the types closely. Some notes and questions:

  1. I am not sure FieldInfoRequest is a good name for the return type of MosaicClient.fields and the type of fields param of queryFieldInfo
  2. Could you explain where column.aggregate is set in the getFieldInfo function? I have added & { aggregate?: boolean } part in FieldInfoRequest for this usecase, but I couldn't find where it's coming from.
  3. The params of summarize has been updated to use FieldInfoRequest.
  4. Stats in field-info.js seems not being used. What's the plan for this variable?

@kwonoh kwonoh requested a review from jheer December 5, 2024 03:06
@@ -27,7 +27,7 @@ export function coordinator(instance) {
}

/**
* @typedef {import('@uwdata/mosaic-sql').Query | string} QueryType
* @typedef {import('@uwdata/mosaic-sql').Query | import('@uwdata/mosaic-sql').DescribeQuery | string} QueryType
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DescribeQuery was missing as a QueryType causing an error

* table: string | import('@uwdata/mosaic-sql').TableRefNode,
* column: (string | import('@uwdata/mosaic-sql').ColumnRefNode) & { aggregate?: boolean },
* stats?: Stat[] | Set<Stat>
* }} FieldInfoRequest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure FieldInfoRequest is a good name for a type that represents the return type of MosaicClient.fields and the type of fields param of queryFieldInfo

*
* @typedef {{
* table: FieldInfoRequest["table"],
* column: string,
Copy link
Contributor Author

@kwonoh kwonoh Dec 5, 2024

Choose a reason for hiding this comment

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

While FieldInfoRequest.column is string | ColumnRefNode, both getFieldInfo and getTableInfo return only string type for column field.

@@ -134,18 +134,20 @@ export class Coordinator {
* or a SQL string.
* @param {object} [options] An options object.
* @param {'arrow' | 'json'} [options.type] The query result format type.
* @param {boolean} [options.cache=true] If true, cache the query result.
* @param {boolean} [options.cache=true] If true, cache the query result in the client (QueryManager).
* @param {boolean} [options.persist=false] If true, persist cached query result in the server.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

persist option was missing in the type definition causing an error

Copy link
Member

Choose a reason for hiding this comment

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

Can you say more about where the error was coming from? I believe persist should be part of the aggregated ...options, not broken out individually.

Copy link
Contributor Author

@kwonoh kwonoh Dec 13, 2024

Choose a reason for hiding this comment

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

Can you say more about where the error was coming from?

The type error was from { persist: true } ingetFieldInfo. Currently, there is no persist field in the options type info of Coordinator.query here.

I believe persist should be part of the aggregated ...options, not broken out individually.

persist type info is added as a member of options object (options.persist not persist), not as a separate field. Do you want to add a new interface type definition for options separately?

or did you mean there should be no default value assignment for persist?

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 now see what you mean. Updated the code.

* @param {number} [options.priority] The query priority, defaults to
* `Priority.Normal`.
* @returns {QueryResult} A query result promise.
*/
query(query, {
type = 'arrow',
cache = true,
persist = false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default value of persist differs depending on the server implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

persist = false, has been removed as it needs to be part of ...options.
But that means the default value of persist should be the same across the servers

@@ -134,18 +134,20 @@ export class Coordinator {
* or a SQL string.
* @param {object} [options] An options object.
* @param {'arrow' | 'json'} [options.type] The query result format type.
* @param {boolean} [options.cache=true] If true, cache the query result.
* @param {boolean} [options.cache=true] If true, cache the query result in the client (QueryManager).
* @param {boolean} [options.persist=false] If true, persist cached query result in the server.
Copy link
Member

Choose a reason for hiding this comment

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

Can you say more about where the error was coming from? I believe persist should be part of the aggregated ...options, not broken out individually.

@kwonoh kwonoh requested a review from jheer December 13, 2024 19:32
@kwonoh kwonoh force-pushed the export-query-field-info-and-js-type branch from 8f4d75f to 1bbfb88 Compare December 13, 2024 20:21
@jheer jheer merged commit dc41a9a into uwdata:main Dec 13, 2024
3 checks passed
@jheer
Copy link
Member

jheer commented Dec 13, 2024

Thanks!

@kwonoh kwonoh deleted the export-query-field-info-and-js-type branch December 16, 2024 15:26
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.

2 participants