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

Interval type support #80

Merged
merged 3 commits into from
Dec 17, 2018
Merged

Interval type support #80

merged 3 commits into from
Dec 17, 2018

Conversation

bpintea
Copy link
Collaborator

@bpintea bpintea commented Dec 15, 2018

This adds support for the interval types:

  • columns and parameters of type interval are now accepted;
  • the driver will perform the translation between ES/SQL's ISO 8601
    representation and the SQL standard;
  • the results/parameters can be converted to/from the permitted data types.

This adds support for the interval types:
- columns of type interval are now accepted;
- the driver will perform the translation between ES/SQL's ISO 8601
  representation and the SQL standard;
- the results can be converted to all permited data types.
@bpintea bpintea mentioned this pull request Dec 15, 2018
Closed
This adds support for parameters of type interval.
The driver will perform the conversion between C values to interval SQL
values within the allowed conversion matrix.
@bpintea bpintea changed the title Interval result support Interval type support Dec 17, 2018
@bpintea
Copy link
Collaborator Author

bpintea commented Dec 17, 2018

The PR is ready for reviewing.

#define TYPE_DOUBLE "DOUBLE"
#define TYPE_BINARY "BINARY"
#define TYPE_OBJECT "OBJECT"
#define TYPE_NESTED "NESTED"
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason for making these upper case?

Maybe it makes no difference, but in the ES docs they're all lower case: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html

There probably is a good reason, but it would be good to add a comment to say why for the benefit of future maintainers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Any particular reason for making these upper case?

I wanted to have them aligned with how ES/SQL reports them, which is upper case. No other reason than that.
The type matching does a case insensitive comparison so either would be fine.

driver/convert.c Outdated
}

/* split by last letter */
switch (wstr->str[wstr->cnt - 1] | 0x20) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the | 0x20 bits are to make the letters lower case? Is this a standard C idiom? I haven't seen it used widely, although I'm a C++ programmer so that might just be ignorance of idiomatic C.

If it's not a mega popular idiom then:

  1. Are you sure it won't cause a subtle bug where a character that's not a letter gets converted to some other character that matches a case?
  2. Even if 1 is not a problem, it might be worth adding a comment to say why the | 0x20 is there.

Alternatively, could towupper be used?

Copy link
Collaborator Author

@bpintea bpintea Dec 17, 2018

Choose a reason for hiding this comment

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

I assume the | 0x20 bits are to make the letters lower case?

Correct.

Is this a standard C idiom?

For the ASCII charset, yes, that's common-ish (as a cheap tolower() alternative). For a whole UTF8 set, this wouldn't work, but SQL keywords only use the ASCII set, so this should be safe.

a character that's not a letter gets converted to some other character that matches a case

This should not happen, since | 0x20 can only increase character's value and the comparison is done against a "full" wide character with a value from within the ASCII subset (i.e. no truncation occurs, which could lead to a false match).

it might be worth adding a comment to say why the | 0x20 is there.

Sure, I'll add it.

- the used `| 0x20` lowers the character, if that has a value in the
ASCII set. add comments to make that clearer.
Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

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

LGTM

@bpintea bpintea merged commit ca990c9 into elastic:master Dec 17, 2018
@bpintea bpintea deleted the feature/intervals branch December 17, 2018 11:22
bpintea added a commit that referenced this pull request Dec 17, 2018
* add interval support

This adds support for the interval types:
- columns of type interval are now accepted;
- the driver will perform the translation between ES/SQL's ISO 8601
  representation and the SQL standard;
- the results can be converted to all permited data types.

* add interval parameter support

This adds support for parameters of type interval.
The driver will perform the conversion between C values to interval SQL
values within the allowed conversion matrix.

* add comment on char lowering in switches

- the used `| 0x20` lowers the character, if that has a value in the
ASCII set. add comments to make that clearer.

(cherry picked from commit ca990c9)
@bpintea bpintea added >feature Applicable to PRs adding new functionality and removed >enhancement labels May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature Applicable to PRs adding new functionality v6.6.0 v6.7.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants