You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2020/06/01 22:37:16 UTC

[asterixdb] branch master updated: [NO ISSUE] Added date/time/datetime support to RangeMapBuilder

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 218a869  [NO ISSUE] Added date/time/datetime support to RangeMapBuilder
218a869 is described below

commit 218a8692f12e5da333264b5d620d9fce3a646f85
Author: Caleb Herbel <ca...@gmail.com>
AuthorDate: Fri May 29 19:49:26 2020 -0600

    [NO ISSUE] Added date/time/datetime support to RangeMapBuilder
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    details:
    -Added date, time, and datetime support to RangeMapBuilder
    -Refactored date and datetime parsing
    -Added runtime tests for RangeMapBuilder
    
    Change-Id: If1a16a1a5dc4d72ba02ac5717d7e30a62a30bc18
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/6403
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
---
 .../sorting/range_hint/range_hint.1.ddl.sqlpp      | 38 +++++++++++
 .../sorting/range_hint/range_hint.10.query.sqlpp   | 24 +++++++
 .../sorting/range_hint/range_hint.2.update.sqlpp   | 39 +++++++++++
 .../sorting/range_hint/range_hint.3.query.sqlpp    | 24 +++++++
 .../sorting/range_hint/range_hint.4.query.sqlpp    | 24 +++++++
 .../sorting/range_hint/range_hint.5.query.sqlpp    | 24 +++++++
 .../sorting/range_hint/range_hint.6.query.sqlpp    | 24 +++++++
 .../sorting/range_hint/range_hint.7.query.sqlpp    | 24 +++++++
 .../sorting/range_hint/range_hint.8.query.sqlpp    | 24 +++++++
 .../sorting/range_hint/range_hint.9.query.sqlpp    | 24 +++++++
 .../results/sorting/range_hint/range_hint.10.adm   |  9 +++
 .../results/sorting/range_hint/range_hint.3.adm    |  9 +++
 .../results/sorting/range_hint/range_hint.4.adm    |  9 +++
 .../results/sorting/range_hint/range_hint.5.adm    |  9 +++
 .../results/sorting/range_hint/range_hint.6.adm    |  9 +++
 .../results/sorting/range_hint/range_hint.7.adm    |  9 +++
 .../results/sorting/range_hint/range_hint.8.adm    |  9 +++
 .../results/sorting/range_hint/range_hint.9.adm    |  9 +++
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  5 ++
 .../external/parser/AbstractDataParser.java        | 27 ++------
 .../asterix/lang/common/util/RangeMapBuilder.java  | 63 ++++++++++++++++-
 .../om/base/temporal/ADateParserFactory.java       | 44 +++++++++++-
 .../om/base/temporal/ADateTimeParserFactory.java   | 79 ++++++++++++++++------
 23 files changed, 514 insertions(+), 45 deletions(-)

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.1.ddl.sqlpp
new file mode 100644
index 0000000..c494b56
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.1.ddl.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  dataverse test if exists;
+create  dataverse test;
+
+use test;
+
+create type test.Schema as
+ closed {
+  id : int,
+  int : int,
+  double : double,
+  string : string,
+  long : bigint,
+  float : float,
+  time : time,
+  date : date,
+  datetime : datetime
+};
+
+create  dataset tsdata(Schema) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.10.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.10.query.sqlpp
new file mode 100644
index 0000000..1f15f5d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.10.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.datetime
+from tsdata as v
+/*+ range [datetime('2007-10-10T16:10:24'), datetime('2011-03-11T16:10:24'), datetime('2015-03-11T16:10:24')] */
+order by v.datetime;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.2.update.sqlpp
new file mode 100644
index 0000000..f914af5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.2.update.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+insert into tsdata
+select element {'id':integer('1'),'int':integer('4'),'double':double('1.4'),'string':'werjk','long':bigint('13334'),'float':float('1.3'),'time':time('23:12:23.938'),'date':date('1904-01-06'),'datetime':datetime('2012-01-12T12:31:39')};
+insert into tsdata
+select element {'id':integer('7'),'int':integer('9'),'double':double('7.2'),'string':"isdfj",'long':bigint('73454'),'float':float('7.2'),'time':time('12:37:10'),'date':date('2194-07-06'),'datetime':datetime('2013-01-12T12:31:39')};
+insert into tsdata
+select element {'id':integer('5'),'int':integer('7'),'double':double('5.3'),'string':"trsdf",'long':bigint('5654'),'float':float('5.2'),'time':time('09:28:10.2'),'date':date('-1904-01-06'),'datetime':datetime('2012-01-12T18:31:39')};
+insert into tsdata
+select element {'id':integer('2'),'int':integer('2'),'double':double('2.1'),'string':"ljkls",'long':bigint('2543'),'float':float('3.6'),'time':time('19:38:23.765'),'date':date('1923-02-08'),'datetime':datetime('2014-02-07T12:29:39')};
+insert into tsdata
+select element {'id':integer('9'),'int':integer('5'),'double':double('9.4'),'string':"sdaf",'long':bigint('943'),'float':float('6.2'),'time':time('11:23:20'),'date':date('2021-02-09'),'datetime':datetime('2014-02-07T13:32:23')};
+insert into tsdata
+select element {'id':integer('8'),'int':integer('3'),'double':double('8.8'),'string':"mfdsa",'long':bigint('82345'),'float':float('4.6'),'time':time('08:24:10.8'),'date':date('-1934-04-08'),'datetime':datetime('2009-02-04T13:34:18')};
+insert into tsdata
+select element {'id':integer('6'),'int':integer('1'),'double':double('7.9'),'string':"asdfb",'long':bigint('72'),'float':float('2.1'),'time':time('16:54:43.123'),'date':date('1989-10-10'),'datetime':datetime('2010-08-11T08:31:39')};
+insert into tsdata
+select element {'id':integer('3'),'int':integer('8'),'double':double('3.1'),'string':"orish",'long':bigint('3543'),'float':float('5.3'),'time':time('02:16:11.3'),'date':date('-2021-02-07'),'datetime':datetime('2006-02-12T17:09:34')};
+insert into tsdata
+select element {'id':integer('4'),'int':integer('6'),'double':double('4.2'),'string':"adffil",'long':bigint('42345'),'float':float('6.3'),'time':time('03:13:10.4'),'date':date('2021-02-07'),'datetime':datetime('2007-03-11T16:10:24')};
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.3.query.sqlpp
new file mode 100644
index 0000000..cbcf7e8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.3.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.int
+from tsdata as v
+/*+ range [2, 4, 10] */
+order by v.int;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.4.query.sqlpp
new file mode 100644
index 0000000..b33a25c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.4.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.double
+from tsdata as v
+/*+ range [2.0, 4.0, 10.0] */
+order by v.double;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.5.query.sqlpp
new file mode 100644
index 0000000..8fba3a7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.5.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.string
+from tsdata as v
+/*+ range ['b', 'n', 'z'] */
+order by v.string;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.6.query.sqlpp
new file mode 100644
index 0000000..3103d7f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.6.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.long
+from tsdata as v
+/*+ range [1000, 10000, 100000] */
+order by v.long;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.7.query.sqlpp
new file mode 100644
index 0000000..87ba5e9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.7.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.float
+from tsdata as v
+/*+ range [2.0F, 4.0F, 10.0F] */
+order by v.float;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.8.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.8.query.sqlpp
new file mode 100644
index 0000000..5d5c318
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.8.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.time
+from tsdata as v
+/*+ range [time('05:28:10.2'), time('12:28:10.2'), time('23:28:10.2')] */
+order by v.time;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.9.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.9.query.sqlpp
new file mode 100644
index 0000000..328216b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sorting/range_hint/range_hint.9.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+select value v.date
+from tsdata as v
+/*+ range [date('2000-01-06'), date('2003-01-06'), date('2200-01-06')] */
+order by v.date;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.10.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.10.adm
new file mode 100644
index 0000000..5b2e7d4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.10.adm
@@ -0,0 +1,9 @@
+datetime("2006-02-12T17:09:34.000Z")
+datetime("2007-03-11T16:10:24.000Z")
+datetime("2009-02-04T13:34:18.000Z")
+datetime("2010-08-11T08:31:39.000Z")
+datetime("2012-01-12T12:31:39.000Z")
+datetime("2012-01-12T18:31:39.000Z")
+datetime("2013-01-12T12:31:39.000Z")
+datetime("2014-02-07T12:29:39.000Z")
+datetime("2014-02-07T13:32:23.000Z")
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.3.adm
new file mode 100644
index 0000000..83b2a16
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.3.adm
@@ -0,0 +1,9 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.4.adm
new file mode 100644
index 0000000..1d977b7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.4.adm
@@ -0,0 +1,9 @@
+1.4
+2.1
+3.1
+4.2
+5.3
+7.2
+7.9
+8.8
+9.4
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.5.adm
new file mode 100644
index 0000000..e48665c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.5.adm
@@ -0,0 +1,9 @@
+"adffil"
+"asdfb"
+"isdfj"
+"ljkls"
+"mfdsa"
+"orish"
+"sdaf"
+"trsdf"
+"werjk"
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.6.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.6.adm
new file mode 100644
index 0000000..c6f53e6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.6.adm
@@ -0,0 +1,9 @@
+72
+943
+2543
+3543
+5654
+13334
+42345
+73454
+82345
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.7.adm
new file mode 100644
index 0000000..04f67f5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.7.adm
@@ -0,0 +1,9 @@
+1.3
+2.1
+3.6
+4.6
+5.2
+5.3
+6.2
+6.3
+7.2
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.8.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.8.adm
new file mode 100644
index 0000000..bd7179f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.8.adm
@@ -0,0 +1,9 @@
+time("02:16:11.300Z")
+time("03:13:10.400Z")
+time("08:24:10.800Z")
+time("09:28:10.200Z")
+time("11:23:20.000Z")
+time("12:37:10.000Z")
+time("16:54:43.123Z")
+time("19:38:23.765Z")
+time("23:12:23.938Z")
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.9.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.9.adm
new file mode 100644
index 0000000..734cd74
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sorting/range_hint/range_hint.9.adm
@@ -0,0 +1,9 @@
+date("-2021-02-07")
+date("-1934-04-08")
+date("-1904-01-06")
+date("1904-01-06")
+date("1923-02-08")
+date("1989-10-10")
+date("2021-02-07")
+date("2021-02-09")
+date("2194-07-06")
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 102b56a..ed56b6e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -255,6 +255,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="sorting">
+      <compilation-unit name="range_hint">
+        <output-dir compare="Text">range_hint</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="sorting">
       <compilation-unit name="records">
         <output-dir compare="Text">records</output-dir>
       </compilation-unit>
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
index 6320a16..cec4b2e 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
@@ -72,10 +72,10 @@ import org.apache.asterix.om.base.ATime;
 import org.apache.asterix.om.base.AUUID;
 import org.apache.asterix.om.base.AYearMonthDuration;
 import org.apache.asterix.om.base.temporal.ADateParserFactory;
+import org.apache.asterix.om.base.temporal.ADateTimeParserFactory;
 import org.apache.asterix.om.base.temporal.ADurationParserFactory;
 import org.apache.asterix.om.base.temporal.ADurationParserFactory.ADurationParseOption;
 import org.apache.asterix.om.base.temporal.ATimeParserFactory;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
@@ -217,31 +217,14 @@ public abstract class AbstractDataParser implements IDataParser {
     }
 
     protected void parseDate(char[] buffer, int begin, int len, DataOutput out) throws HyracksDataException {
-        long chrononTimeInMs = ADateParserFactory.parseDatePart(buffer, begin, len);
-        short temp = 0;
-        if (chrononTimeInMs < 0 && chrononTimeInMs % GregorianCalendarSystem.CHRONON_OF_DAY != 0) {
-            temp = 1;
-        }
-        aDate.setValue((int) (chrononTimeInMs / GregorianCalendarSystem.CHRONON_OF_DAY) - temp);
+        int chrononTimeInDays = ADateParserFactory.parseDatePartInDays(buffer, begin, len);
+        aDate.setValue(chrononTimeInDays);
         dateSerde.serialize(aDate, out);
     }
 
     protected void parseDateTime(char[] buffer, int begin, int len, DataOutput out) throws HyracksDataException {
-        // +1 if it is negative (-)
-
-        int timeOffset = (buffer[begin] == '-') ? 1 : 0;
-
-        timeOffset = timeOffset + 8 + begin;
-
-        if (buffer[timeOffset] != 'T') {
-            timeOffset += 2;
-            if (buffer[timeOffset] != 'T') {
-                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_INTERVAL_INVALID_DATETIME);
-            }
-        }
-        long chrononTimeInMs = ADateParserFactory.parseDatePart(buffer, begin, timeOffset - begin);
-        chrononTimeInMs += ATimeParserFactory.parseTimePart(buffer, timeOffset + 1, begin + len - timeOffset - 1);
-        aDateTime.setValue(chrononTimeInMs);
+        long chrononDatetimeInMs = ADateTimeParserFactory.parseDateTimePart(buffer, begin, len);
+        aDateTime.setValue(chrononDatetimeInMs);
         datetimeSerde.serialize(aDateTime, out);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/RangeMapBuilder.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/RangeMapBuilder.java
index 89f1347..2d749d2 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/RangeMapBuilder.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/RangeMapBuilder.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.lang.common.util;
 
+import static org.apache.asterix.om.base.temporal.ATimeParserFactory.parseTimePart;
+
 import java.io.DataOutput;
 import java.util.List;
 
@@ -29,6 +31,7 @@ import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
 import org.apache.asterix.lang.common.base.Literal;
+import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.ListConstructor;
 import org.apache.asterix.lang.common.expression.LiteralExpr;
 import org.apache.asterix.lang.common.literal.DoubleLiteral;
@@ -36,11 +39,18 @@ import org.apache.asterix.lang.common.literal.FloatLiteral;
 import org.apache.asterix.lang.common.literal.IntegerLiteral;
 import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
 import org.apache.asterix.lang.common.literal.StringLiteral;
+import org.apache.asterix.om.base.AMutableDate;
+import org.apache.asterix.om.base.AMutableDateTime;
 import org.apache.asterix.om.base.AMutableDouble;
 import org.apache.asterix.om.base.AMutableFloat;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableString;
+import org.apache.asterix.om.base.AMutableTime;
+import org.apache.asterix.om.base.temporal.ADateParserFactory;
+import org.apache.asterix.om.base.temporal.ADateTimeParserFactory;
+import org.apache.asterix.om.base.temporal.ATimeParserFactory;
+import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
@@ -48,6 +58,7 @@ import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.HyracksException;
 import org.apache.hyracks.api.exceptions.SourceLocation;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.partition.range.RangeMap;
@@ -59,7 +70,7 @@ public class RangeMapBuilder {
 
     public static RangeMap parseHint(Expression expression) throws CompilationException {
         if (expression.getKind() != Kind.LIST_CONSTRUCTOR_EXPRESSION) {
-            throw new CompilationException("The range hint must be a list.");
+            throw new CompilationException(ErrorCode.RANGE_MAP_ERROR, expression.getSourceLocation());
         }
 
         ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
@@ -74,8 +85,11 @@ public class RangeMapBuilder {
             if (item.getKind() == Kind.LITERAL_EXPRESSION) {
                 parseLiteralToBytes((LiteralExpr) item, out);
                 offsets[i] = abvs.getLength();
+            } else if (item.getKind() == Kind.CALL_EXPRESSION) {
+                parseExpressionToBytes((CallExpr) item, out);
+                offsets[i] = abvs.getLength();
             } else {
-                throw new CompilationException("Expected literal in the range hint");
+                throw new CompilationException(ErrorCode.RANGE_MAP_ERROR, expression.getSourceLocation());
             }
             // TODO Add support for composite fields.
         }
@@ -84,6 +98,51 @@ public class RangeMapBuilder {
     }
 
     @SuppressWarnings("unchecked")
+    private static void parseExpressionToBytes(CallExpr item, DataOutput out) throws CompilationException {
+        AMutableDate aDate = new AMutableDate(0);
+        AMutableTime aTime = new AMutableTime(0);
+        AMutableDateTime aDateTime = new AMutableDateTime(0L);
+        @SuppressWarnings("rawtypes")
+        ISerializerDeserializer serde;
+
+        //Check if Literal
+        if (!(item.getExprList().get(0).getKind() == Kind.LITERAL_EXPRESSION)) {
+            throw new CompilationException(ErrorCode.RANGE_MAP_ERROR, item.getSourceLocation());
+        }
+        LiteralExpr argumentLiteralExpr = (LiteralExpr) item.getExprList().get(0);
+
+        //Make Sure Literal is String Type
+        if (!(argumentLiteralExpr.getValue().getLiteralType() == Literal.Type.STRING)) {
+            throw new CompilationException(ErrorCode.RANGE_MAP_ERROR, item.getSourceLocation());
+        }
+        String value = argumentLiteralExpr.getValue().toString();
+
+        try {
+            if (BuiltinFunctions.DATE_CONSTRUCTOR.getName().equals(item.getFunctionSignature().getName())) {
+                int chrononTimeInDays = ADateParserFactory.parseDatePartInDays(value, 0, value.length());
+                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATE);
+                aDate.setValue(chrononTimeInDays);
+                serde.serialize(aDate, out);
+            } else if (BuiltinFunctions.TIME_CONSTRUCTOR.getName().equals(item.getFunctionSignature().getName())) {
+                int chrononTimeInMillis = ATimeParserFactory.parseTimePart(value, 0, value.length());
+                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);
+                aTime.setValue(chrononTimeInMillis);
+                serde.serialize(aTime, out);
+            } else if (BuiltinFunctions.DATETIME_CONSTRUCTOR.getName().equals(item.getFunctionSignature().getName())) {
+                long chronoDatetimeInMills = ADateTimeParserFactory.parseDateTimePart(value, 0, value.length());
+                aDateTime.setValue(chronoDatetimeInMills);
+                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
+                serde.serialize(aDateTime, out);
+            } else {
+                throw new NotImplementedException("The range map builder has not been implemented for "
+                        + item.getFunctionSignature().getName() + " type of expressions.");
+            }
+        } catch (HyracksException e) {
+            throw new CompilationException(ErrorCode.RANGE_MAP_ERROR, e, item.getSourceLocation(), e.getMessage());
+        }
+    }
+
+    @SuppressWarnings("unchecked")
     private static void parseLiteralToBytes(LiteralExpr item, DataOutput out) throws CompilationException {
         AMutableDouble aDouble = new AMutableDouble(0);
         AMutableFloat aFloat = new AMutableFloat(0);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateParserFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateParserFactory.java
index 35691a1..a4abbd6 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateParserFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateParserFactory.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.om.base.temporal;
 
+import static org.apache.asterix.om.base.temporal.GregorianCalendarSystem.CHRONON_OF_DAY;
+
 import java.io.DataOutput;
 import java.io.IOException;
 
@@ -58,9 +60,7 @@ public class ADateParserFactory implements IValueParserFactory {
      * Parse the given char sequence as a date string, and return the milliseconds represented by the date.
      *
      * @param dateString
-     *            accessor for the char sequence
      * @param start
-     *            indicating whether it is a single date string, or it is the date part of a datetime string
      * @param length
      * @return
      * @throws Exception
@@ -342,4 +342,44 @@ public class ADateParserFactory implements IValueParserFactory {
 
         return GregorianCalendarSystem.getInstance().getChronon(year, month, day, 0, 0, 0, 0, 0);
     }
+
+    /**
+     * Parse the given string sequence as a date string, and return the days represented by the date.
+     *
+     * @param dateString
+     * @param start
+     * @param length
+     * @return
+     * @throws Exception
+     */
+    public static int parseDatePartInDays(String dateString, int start, int length) throws HyracksDataException {
+        long chronon = parseDatePart(dateString, start, length);
+        return convertParsedMillisecondsToDays(chronon);
+    }
+
+    /**
+     * Parse the given string sequence as a date string, and return the days represented by the date.
+     *
+     * @param dateString
+     * @param start
+     * @param length
+     * @return
+     * @throws Exception
+     */
+    public static int parseDatePartInDays(char[] dateString, int start, int length) throws HyracksDataException {
+        long chronon = parseDatePart(dateString, start, length);
+        return convertParsedMillisecondsToDays(chronon);
+    }
+
+    public static int convertParsedMillisecondsToDays(long chronon) throws HyracksDataException {
+        if (chronon >= 0) {
+            return (int) (chronon / CHRONON_OF_DAY);
+        } else {
+            if (chronon % CHRONON_OF_DAY != 0) {
+                return (int) (chronon / CHRONON_OF_DAY - 1);
+            } else {
+                return (int) (chronon / CHRONON_OF_DAY);
+            }
+        }
+    }
 }
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateTimeParserFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateTimeParserFactory.java
index f9e53b9..88789db 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateTimeParserFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/temporal/ADateTimeParserFactory.java
@@ -44,26 +44,9 @@ public class ADateTimeParserFactory implements IValueParserFactory {
 
             @Override
             public boolean parse(char[] buffer, int start, int length, DataOutput out) throws HyracksDataException {
-                long chrononTimeInMs = 0;
-
-                short timeOffset = (short) ((buffer[start] == '-') ? 1 : 0);
-
-                timeOffset += 8;
-
-                if (buffer[start + timeOffset] != 'T') {
-                    timeOffset += 2;
-                    if (buffer[start + timeOffset] != 'T') {
-                        throw new HyracksDataException(dateTimeErrorMessage + ": missing T");
-                    }
-                }
-
-                chrononTimeInMs = ADateParserFactory.parseDatePart(buffer, start, timeOffset);
-
-                chrononTimeInMs +=
-                        ATimeParserFactory.parseTimePart(buffer, start + timeOffset + 1, length - timeOffset - 1);
-
+                long parsedDateTime = parseDateTimePart(buffer, start, length);
                 try {
-                    out.writeLong(chrononTimeInMs);
+                    out.writeLong(parsedDateTime);
                     return true;
                 } catch (IOException ex) {
                     throw HyracksDataException.create(ex);
@@ -72,4 +55,62 @@ public class ADateTimeParserFactory implements IValueParserFactory {
         };
     }
 
+    /**
+     * Parse the given char sequence as a datetime string, and return the milliseconds represented by the date and time.
+     *
+     * @param dateTimeString
+     * @param start
+     * @param length
+     * @return
+     * @throws Exception
+     */
+    public static long parseDateTimePart(String dateTimeString, int start, int length) throws HyracksDataException {
+        long chrononTimeInMs = 0;
+
+        short timeOffset = (short) ((dateTimeString.charAt(start) == '-') ? 1 : 0);
+
+        timeOffset += 8;
+
+        if (dateTimeString.charAt(start + timeOffset) != 'T') {
+            timeOffset += 2;
+            if (dateTimeString.charAt(start + timeOffset) != 'T') {
+                throw new HyracksDataException(dateTimeErrorMessage + ": missing T");
+            }
+        }
+
+        chrononTimeInMs = ADateParserFactory.parseDatePart(dateTimeString, start, timeOffset);
+
+        return chrononTimeInMs
+                + ATimeParserFactory.parseTimePart(dateTimeString, start + timeOffset + 1, length - timeOffset - 1);
+    }
+
+    /**
+     * A copy-and-paste of {@link #parseDateTimePart(String, int, int)} but for a char array, in order
+     * to avoid object creation.
+     *
+     * @param dateTimeString
+     * @param start
+     * @param length
+     * @return
+     * @throws HyracksDataException
+     */
+    public static long parseDateTimePart(char[] dateTimeString, int start, int length) throws HyracksDataException {
+        long chrononTimeInMs = 0;
+
+        short timeOffset = (short) ((dateTimeString[start] == '-') ? 1 : 0);
+
+        timeOffset += 8;
+
+        if (dateTimeString[start + timeOffset] != 'T') {
+            timeOffset += 2;
+            if (dateTimeString[start + timeOffset] != 'T') {
+                throw new HyracksDataException(dateTimeErrorMessage + ": missing T");
+            }
+        }
+
+        chrononTimeInMs = ADateParserFactory.parseDatePart(dateTimeString, start, timeOffset);
+
+        return chrononTimeInMs
+                + ATimeParserFactory.parseTimePart(dateTimeString, start + timeOffset + 1, length - timeOffset - 1);
+    }
 }