Skip to content

Conversation

@atzoum
Copy link
Collaborator

@atzoum atzoum commented Sep 9, 2024

Description

Introducing the following methods.

// QueryCondition returns a dialect-specific query condition sql string for the provided identifier, operator and value(s).
//
// E.g. QueryCondition("age", "gt", 18) returns "age > 18"
//
// Each operator has a different number of arguments, e.g. [eq] requires one argument, [in] requires at least one argument, etc.
// See [op] package for the list of supported operators
QueryCondition(identifier, operator string, args ...any) (sql string, err error)

// TimestampAdd returns an expression that adds the interval to the timestamp value.
// The value can either be a string literal (column, timestamp, function etc.) or a [time.Time] value.
TimestampAdd(timeValue any, interval int, unit string) (Expression, error)

// DateAdd returns an expression that adds the interval to the date value.
// The value can either be a string literal (column, timestamp, function etc.) or a [time.Time] value.
// Values are cast to [DATE].
DateAdd(dateValue any, interval int, unit string) (Expression, error)

Using goqu internally which:

  • Provides proper go type(s) recognition in parameters (int, float, string, time.Time, etc.)
  • It properly escapes special characters from string values (')
  • It handles differences in warehouse dialects seamlessly eg. bool_col IS TRUE vs bool_col = 'TRUE'.

Linear Ticket

resolves PRO-3401

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@codecov
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 96.31068% with 19 lines in your changes missing coverage. Please review.

Project coverage is 87.04%. Comparing base (8cab1fd) to head (da28b2b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sqlconnect/internal/base/goqu_dialect.go 89.14% 13 Missing and 1 partial ⚠️
sqlconnect/op/operator.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #180      +/-   ##
==========================================
+ Coverage   85.58%   87.04%   +1.46%     
==========================================
  Files          78       87       +9     
  Lines        3343     3851     +508     
==========================================
+ Hits         2861     3352     +491     
- Misses        328      345      +17     
  Partials      154      154              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@atzoum atzoum force-pushed the feat.filterCondition branch 3 times, most recently from 7a1a31d to cebc595 Compare September 10, 2024 10:38
@atzoum atzoum changed the title [WIP] feat: support dialect-aware query conditions feat: support dialect-aware query conditions Sep 10, 2024
@atzoum atzoum force-pushed the feat.filterCondition branch from cebc595 to 6854d81 Compare September 10, 2024 12:02
@atzoum atzoum marked this pull request as ready for review September 10, 2024 14:17
@atzoum atzoum requested a review from kuldeep0020 September 11, 2024 08:36
Copy link

@shubhammehra4 shubhammehra4 left a comment

Choose a reason for hiding this comment

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

LGTM

@atzoum atzoum force-pushed the feat.filterCondition branch from 588fd0a to 2308aef Compare September 12, 2024 07:09
// v < left OR v > right
NotBetween Operator = "notbetween"
// left >= now() - INTERVAL right
NbfInterval Operator = "nbfinterval"
Copy link

Choose a reason for hiding this comment

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

The key nbfinterval is not clear to me. Can we give it a clearer name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Open to suggestions! nbf prefix stands for not before.

Copy link

Choose a reason for hiding this comment

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

Instead can we have something like
beforeintervalbounded & beforeintervalunbounded
afterintervalbounded & afterintervalunbounded

Copy link

Choose a reason for hiding this comment

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

Also, we can use camelCase or snake case operators. Will make things much clearer. Especially in case we are using bigger ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

imo operators should be kept small and case insensitive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what about:
gti --> gt an interval
gtei --> gte an interval
lti --> less than an interval
ltei --> less than an interval
betweeni --> between an interval

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another option would be to keep using gt, gte, lt, lte, between, etc. and allow a special value format for intervals, e.g. "now-1d"

Copy link
Collaborator Author

@atzoum atzoum Sep 12, 2024

Choose a reason for hiding this comment

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

finally, we can just keep ti simple for now and name it inlast

Copy link

@sprksh sprksh left a comment

Choose a reason for hiding this comment

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

Went through the code and tests. Looks great.

// NOT LIKE
NotLike Operator = "notlike"
// left <= v <= right
Between Operator = "between"
Copy link

Choose a reason for hiding this comment

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

For Between, Should we think of some way to specify left and right bounded/unbounded conditions.

Copy link

Choose a reason for hiding this comment

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

Also NotBetween

@atzoum atzoum merged commit 08906ee into main Sep 12, 2024
@atzoum atzoum deleted the feat.filterCondition branch September 12, 2024 10:26
atzoum pushed a commit that referenced this pull request Sep 12, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.10.0](v1.9.0...v1.10.0)
(2024-09-12)


### Features

* **databricks:** bump github.com/databricks/databricks-sql-go from
1.6.0 to 1.6.1
([#174](#174))
([8cab1fd](8cab1fd))
* **snowflake:** bump github.com/snowflakedb/gosnowflake from 1.10.1 to
1.11.1 ([#171](#171))
([e64ba77](e64ba77))
* support dialect-aware query conditions
([#180](#180))
([08906ee](08906ee))


### Miscellaneous

* all warehouses support views in ListTables
([#169](#169))
([098a378](098a378))
* **deps:** bump github.com/aws/aws-sdk-go-v2/credentials from 1.17.27
to 1.17.32
([#179](#179))
([47afb2e](47afb2e))
* **deps:** bump github.com/rudderlabs/rudder-go-kit from 0.36.2 to
0.40.0 ([#178](#178))
([a4ee52e](a4ee52e))
* **deps:** bump google.golang.org/api from 0.194.0 to 0.196.0
([#177](#177))
([aaee20d](aaee20d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

3 participants