namhnguyen / asterixdb

Automatically exported from code.google.com/p/asterixdb
0 stars 0 forks source link

Type conversion/casting broken for predicates #716

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following AQL statement should produce a result containing the single 
record that was inserted, but it doesn't. 

----------------------------------------------
drop dataverse fooverse;
create dataverse fooverse;
use dataverse fooverse;

create type footype as open {
id:int64
}

create dataset fooset(footype) primary key id;

insert into dataset fooset(
{"id": 1}
);

for $f in dataset fooset
where $f.id = 1
return $f
----------------------------------------------

The following AQL statement produces the correct result, but requires an 
explicit type conversion from the user:

----------------------------------------------
for $f in dataset fooset
where $f.id = int64("1")
return $f
----------------------------------------------

Original issue reported on code.google.com by zheilb...@gmail.com on 14 Feb 2014 at 1:48

GoogleCodeExporter commented 9 years ago
Investigated the issue a bit... Problem is that the insert path and query path 
are treated differently. The insert path will introduce type casting, but the 
query path will not. In particular, search predicates that are passed to 
indexes may, in general, need to be type casted.

Original comment by zheilb...@gmail.com on 6 Jun 2014 at 8:17

GoogleCodeExporter commented 9 years ago
Let's squash this bug!  Maybe Yingyi can peek since he has the most typecasting 
expertise - Yingyi, can you have a look at this?  (Or help Taewoo look at it 
since we may have a load path issue as well, if you can't look at it and fix it 
right now?)

Original comment by dtab...@gmail.com on 17 Sep 2014 at 2:04

GoogleCodeExporter commented 9 years ago
Simple reusing of current type casting operator might not work for this case, 
since it's working only with records whereas predicates use individual fields

Original comment by ildar.absalyamov on 17 Sep 2014 at 5:10

GoogleCodeExporter commented 9 years ago
We do need to clean this all up!  Also we need to fix our int story - to be 
int64 by default, smaller if specified (only if so).

Original comment by dtab...@gmail.com on 17 Sep 2014 at 5:04

GoogleCodeExporter commented 9 years ago
I have gathered some information about integer type, some platform uses 32bit 
as default, some uses 64bit as default. The following text is brought from the 
URL that I mentioned. 

1. SQL 2003 Standard
http://sigmod.org/publications/sigmod-record/0403/E.JimAndrew-standard.pdf
The BIGINT data type is a new numerical type similar to the existing SMALLINT 
and INTEGER types, just with a greater precision (or more precisely, a 
precision no smaller). Though a particular precision for an INTEGER type (or 
any of the other numerical data types) is not mandated in the SQL standard, 
actual implementations in general support 32-bit INTEGER values. Those 
implementations then usually support 64-bit BIGINT values.

2. MYSQL
http://dev.mysql.com/doc/refman/5.0/en/integer-types.html
Name:INT    
Range:-2147483648 ~ 2147483647

3. Oracle
http://docs.oracle.com/cd/E21901_01/doc/timesten.1122/e21642/types.htm#TTSQL126
Name:NUMBER(38,0) or TT_INTEGER
Range:-2147483648 ~ 2147483647

4. MongoDB
1) 32-bit Platforms
Numbers without decimal points will be saved as 32-bit integers. To save a 
number as a 64-bit integer, use bigint.

2) 64-bit Platforms
Numbers without a decimal point will be saved and returned as 64-bit integers. 
Note that there is no way to save a 32-bit int on a 64-bit machine.

5. Java
int: By default, the int data type is a 32-bit signed two's complement integer, 
which has a minimum value of -2^31 and a maximum value of 2^31-1. In Java SE 8 
and later, you can use the int data type to represent an unsigned 32-bit 
integer, which has a minimum value of 0 and a maximum value of 2^32-1. Use the 
Integer class to use int data type as an unsigned integer. See the section The 
Number Classes for more information. Static methods like compareUnsigned, 
divideUnsigned etc have been added to the Integer class to support the 
arithmetic operations for unsigned integers.

long: The long data type is a 64-bit two's complement integer. The signed long 
has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and 
later, you can use the long data type to represent an unsigned 64-bit long, 
which has a minimum value of 0 and a maximum value of 264-1. Use this data type 
when you need a range of values wider than those provided by int. The Long 
class also contains methods like compareUnsigned, divideUnsigned etc to support 
arithmetic operations for unsigned long.

6. Python
There are four distinct numeric types: plain integers, long integers, floating 
point numbers, and complex numbers. In addition, Booleans are a subtype of 
plain integers. Plain integers (also just called integers) are implemented 
using long in C, which gives them at least 32 bits of precision (sys.maxint is 
always set to the maximum plain integer value for the current platform, the 
minimum value is -sys.maxint - 1). Long integers have unlimited precision. 

Original comment by wangs...@gmail.com on 17 Sep 2014 at 5:28

GoogleCodeExporter commented 9 years ago
You forgot about the most important language: XQuery/XML Schema ;)
There xs:integer and xs:decimal are of arbitrary precision and have a huge 
number of different precision subtypes 
(http://www.w3.org/TR/xmlschema-2/#built-in-datatypes).

But I think that for us one of the questions is, if we need to have different 
integer types or if we can just have one type and that's 64-bit. Obviously, 
this might increase storage consumption a bit (unless we introduce a nice, 
variable-length encoding), but at the HTTP interface level we anyway provide 
text and the client anyway has to parse/convert the text ...

I think that we discussed this option before, but I don't remember the 
conclusion ...

Original comment by westm...@gmail.com on 18 Sep 2014 at 12:05

GoogleCodeExporter commented 9 years ago
We also have this issue: 
https://code.google.com/p/asterixdb/issues/detail?id=644
but ti doesn't contain more info either.

Original comment by westm...@gmail.com on 18 Sep 2014 at 12:08

GoogleCodeExporter commented 9 years ago

Original comment by buyingyi@gmail.com on 13 Oct 2014 at 10:03

GoogleCodeExporter commented 9 years ago

Original comment by wangs...@gmail.com on 13 Nov 2014 at 3:20

GoogleCodeExporter commented 9 years ago
Type Casting is now applied among numeric types. 

Original comment by wangs...@gmail.com on 11 Dec 2014 at 6:47

GoogleCodeExporter commented 9 years ago

Original comment by wangs...@gmail.com on 6 Mar 2015 at 4:43