(feat) more data types#5
Conversation
…entions, improving handling of arrays and nested objects, and ensuring accurate data representation in Looker Studio.
There was a problem hiding this comment.
Hello @teetangh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request enhances the data type handling within the getSchema function of the columnar connector. It introduces heuristic type refinement based on field names, aiming to provide more accurate and specific Looker Studio types. The changes include logic to infer types like PERCENT, DURATION, CURRENCY, DATETIME, GEO, and URL based on naming conventions. Additionally, the code now converts field names to lowercase for case-insensitive matching during type refinement.
Highlights
- Type Refinement: Implements heuristic type refinement based on field names to infer more specific Looker Studio types (e.g., PERCENT, DURATION, CURRENCY, DATETIME, GEO, URL).
- Case-Insensitive Matching: Converts field names to lowercase for case-insensitive matching during type refinement.
- Array Handling: Arrays are represented as a single STRING field.
Changelog
- src/columnar/connector.gs
- Added logic to convert field names to lowercase for case-insensitive matching.
- Implemented heuristic type refinement for NUMBER fields to infer PERCENT, DURATION, and CURRENCY types based on field name.
- Implemented heuristic type refinement for STRING fields to infer DATETIME, GEO, and URL types based on field name.
- Modified the semantics object to include isReaggregatable for METRIC types.
- Updated logging to include concept type for added fields.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A string, a number, a date,
In Looker's realm, we elevate.
By names they're known,
Their types are shown,
A richer view, we create.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request introduces heuristic type refinement based on field names, which enhances the schema inference for Looker Studio. This is a valuable addition, but there are areas where the logic can be improved for clarity and maintainability.
Summary of Findings
- Type refinement heuristics: The heuristic type refinement logic is complex and could benefit from being broken down into smaller, more manageable functions. This would improve readability and testability.
- Logging consistency: The logging statements within the type refinement logic are verbose. Consider consolidating these into a single, more informative log message per refinement.
- Potential for false positives: The heuristic type refinement relies on simple string matching, which may lead to false positives. Consider adding more robust checks or allowing users to override the inferred types.
Merge Readiness
The changes introduce valuable heuristic type refinement. However, the complexity of the refinement logic and the potential for false positives warrant careful consideration. I recommend addressing the identified issues before merging to ensure the reliability and maintainability of the code. I am unable to approve this pull request, and recommend that others review and approve this code before merging.
| if (lowerFieldName.includes('percent') || lowerFieldName.includes('rate') || lowerFieldName.includes('%')) { | ||
| lookerType = 'PERCENT'; | ||
| Logger.log('Refined type for [%s] to PERCENT based on name.', fieldName); |
There was a problem hiding this comment.
| } else if (lowerFieldName.includes('duration') || lowerFieldName.includes('_sec') || lowerFieldName.endsWith('seconds')) { | ||
| lookerType = 'DURATION'; | ||
| Logger.log('Refined type for [%s] to DURATION based on name.', fieldName); |
| } else if (lowerFieldName.includes('amount') || lowerFieldName.includes('price') || lowerFieldName.includes('cost') || lowerFieldName.includes('revenue') || lowerFieldName.includes('salary') || lowerFieldName.includes('currency') || lowerFieldName.includes('$') || lowerFieldName.includes('€') || lowerFieldName.includes('£') || lowerFieldName.includes('¥')) { | ||
| lookerType = 'CURRENCY'; | ||
| Logger.log('Refined type for [%s] to CURRENCY based on name.', fieldName); |
| if (lowerFieldName.includes('date') || lowerFieldName.includes('time') || lowerFieldName.includes('timestamp') || lowerFieldName.match(/_dt$|_ts$/) || lowerFieldName.startsWith('dt_') || lowerFieldName.startsWith('ts_') ) { | ||
| // Use DATETIME as it's more general. Looker can format it. | ||
| lookerType = 'DATETIME'; | ||
| Logger.log('Refined type for [%s] to DATETIME based on name.', fieldName); |
There was a problem hiding this comment.
| } else if (lowerFieldName.includes('country') || lowerFieldName.includes('city') || lowerFieldName.includes('region') || lowerFieldName.includes('state') || lowerFieldName.includes('zip') || lowerFieldName.includes('postal') || lowerFieldName.includes('latitude') || lowerFieldName.includes('longitude') || lowerFieldName.includes('lat') || lowerFieldName.includes('lon') || lowerFieldName.match(/_geo$|_location$/)) { | ||
| lookerType = 'GEO'; | ||
| Logger.log('Refined type for [%s] to GEO based on name.', fieldName); |
| } else if (lowerFieldName.includes('url') || lowerFieldName.includes('link') || lowerFieldName.includes('website') || lowerFieldName.startsWith('http')) { | ||
| lookerType = 'URL'; | ||
| Logger.log('Refined type for [%s] to URL based on name.', fieldName); |
No description provided.