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

Stop guessing data type in the client side #3553

Open
2 tasks
arikfr opened this issue Mar 7, 2019 · 3 comments
Open
2 tasks

Stop guessing data type in the client side #3553

arikfr opened this issue Mar 7, 2019 · 3 comments

Comments

@arikfr
Copy link
Member

arikfr commented Mar 7, 2019

For reasons I no longer remember, we guess the column data type in the client side code:

forOwn(row, (v, k) => {
let newType = null;
if (isNumber(v)) {
newType = 'float';
} else if (isString(v) && v.match(/^\d{4}-\d{2}-\d{2}T/)) {
row[k] = moment.utc(v);
newType = 'datetime';
} else if (isString(v) && v.match(/^\d{4}-\d{2}-\d{2}$/)) {
row[k] = moment.utc(v);
newType = 'date';
} else if (typeof v === 'object' && v !== null) {
row[k] = JSON.stringify(v);
} else {
newType = 'string';
}
if (newType !== null) {
if (columnTypes[k] !== undefined && columnTypes[k] !== newType) {
columnTypes[k] = 'string';
} else {
columnTypes[k] = newType;
}
}
});

While this has some upsides (not all data sources return proper types) it also has downsides. Sometimes users want more control over their data representation, which this type guessing overrides.

  • Remove type guessing from the client side
  • Make sure all query runners apply correct types where possible

This is open for discussion, and if someone thinks we should keep current behavior -- please speak.

@kravets-levko
Copy link
Collaborator

@arikfr How about data types such as date/time which is not JSON-serializable?

@arikfr
Copy link
Member Author

arikfr commented Mar 7, 2019

@kravets-levko when the server reports something as date/time, we will convert it to a date/time object (moment). But we won't do this just because it follows a certain pattern.

@FJK-NZ-zz
Copy link

I'm wondering if this is causing the issue I'm having where it appears that "sorting" values on a chart defaults values to "strings".

I.e if you have integers:
1 , 2, 10, 20 if you sort them on the chart settings it returns this order:

1, 10, 2, 20

You can test with:
If you create a bar chart from this SQL and try order the x column
with data as ( Select 1 as x , 1 as y union Select 2 as x, 2 as y union Select 10 as x, 10 as y union Select 20 as x, 20 as y ) Select * from data

You get:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants