Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 559CF200B79 for ; Wed, 7 Sep 2016 11:25:33 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 54769160AB1; Wed, 7 Sep 2016 09:25:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D1979160ADC for ; Wed, 7 Sep 2016 11:25:30 +0200 (CEST) Received: (qmail 54125 invoked by uid 500); 7 Sep 2016 09:25:30 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 53708 invoked by uid 99); 7 Sep 2016 09:25:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2016 09:25:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7BAAAEF793; Wed, 7 Sep 2016 09:25:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Wed, 07 Sep 2016 09:25:41 -0000 Message-Id: In-Reply-To: <6ec7c925f6ef4b69af4c9d6881dee058@git.apache.org> References: <6ec7c925f6ef4b69af4c9d6881dee058@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/28] ignite git commit: IGNITE-3750: ODBC: Added tests for date/time types. This closes #1002. archived-at: Wed, 07 Sep 2016 09:25:33 -0000 IGNITE-3750: ODBC: Added tests for date/time types. This closes #1002. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a7609187 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a7609187 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a7609187 Branch: refs/heads/ignite-1.6.7-test Commit: a760918757bee71ab28495496f94e9067ef17888 Parents: 3aa13f7 Author: Igor Sapego Authored: Mon Sep 5 10:36:38 2016 +0300 Committer: vozerov-gridgain Committed: Mon Sep 5 10:36:38 2016 +0300 ---------------------------------------------------------------------- .../processors/odbc/OdbcMessageParser.java | 10 +- modules/platforms/cpp/odbc-test/Makefile.am | 1 + .../odbc-test/include/sql_test_suite_fixture.h | 6 + .../cpp/odbc-test/project/vs/odbc-test.vcxproj | 1 + .../project/vs/odbc-test.vcxproj.filters | 3 + .../cpp/odbc-test/src/queries_test.cpp | 1 + .../src/sql_date_time_functions_test.cpp | 213 +++++++++++++++++++ .../odbc-test/src/sql_test_suite_fixture.cpp | 17 ++ modules/platforms/cpp/odbc/src/column.cpp | 14 +- .../cpp/odbc/src/config/connection_info.cpp | 16 +- 10 files changed, 261 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcMessageParser.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcMessageParser.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcMessageParser.java index a751eb2..3accf74 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcMessageParser.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcMessageParser.java @@ -232,8 +232,14 @@ public class OdbcMessageParser { writer.writeInt(row.size()); - for (Object obj : row) - writer.writeObjectDetached(obj); + for (Object obj : row) { + if (obj instanceof java.sql.Timestamp) + writer.writeTimestamp((java.sql.Timestamp)obj); + else if (obj instanceof java.util.Date) + writer.writeDate((java.util.Date)obj); + else + writer.writeObjectDetached(obj); + } } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc-test/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/Makefile.am b/modules/platforms/cpp/odbc-test/Makefile.am index c3dd86a..a22e247 100644 --- a/modules/platforms/cpp/odbc-test/Makefile.am +++ b/modules/platforms/cpp/odbc-test/Makefile.am @@ -70,6 +70,7 @@ ignite_odbc_tests_SOURCES = \ src/sql_operators_test.cpp \ src/sql_value_expressions_test.cpp \ src/sql_types_test.cpp \ + src/sql_date_time_functions_test.cpp \ src/sql_outer_join_test.cpp \ ../odbc/src/cursor.cpp \ ../odbc/src/config/connection_info.cpp \ http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc-test/include/sql_test_suite_fixture.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/include/sql_test_suite_fixture.h b/modules/platforms/cpp/odbc-test/include/sql_test_suite_fixture.h index 9e482da..6d26818 100644 --- a/modules/platforms/cpp/odbc-test/include/sql_test_suite_fixture.h +++ b/modules/platforms/cpp/odbc-test/include/sql_test_suite_fixture.h @@ -186,6 +186,12 @@ namespace ignite template<> void SqlTestSuiteFixture::CheckSingleResult(const char* request); + + template<> + void SqlTestSuiteFixture::CheckSingleResult(const char* request); + + template<> + void SqlTestSuiteFixture::CheckSingleResult(const char* request); } #endif //_IGNITE_ODBC_TEST_SQL_TEST_SUIT_FIXTURE http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj index b85f1e6..98a1e58 100644 --- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj +++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj @@ -171,6 +171,7 @@ + http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters index ee5df76..f348ee7 100644 --- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters +++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters @@ -109,6 +109,9 @@ Code + + Code + http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc-test/src/queries_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/queries_test.cpp b/modules/platforms/cpp/odbc-test/src/queries_test.cpp index 4ba3a63..7c10527 100644 --- a/modules/platforms/cpp/odbc-test/src/queries_test.cpp +++ b/modules/platforms/cpp/odbc-test/src/queries_test.cpp @@ -121,6 +121,7 @@ struct QueriesTestSuiteFixture cfg.jvmOpts.push_back("-Djava.compiler=NONE"); cfg.jvmOpts.push_back("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"); cfg.jvmOpts.push_back("-XX:+HeapDumpOnOutOfMemoryError"); + cfg.jvmOpts.push_back("-Duser.timezone=GMT"); #ifdef IGNITE_TESTS_32 cfg.jvmInitMem = 256; http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc-test/src/sql_date_time_functions_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/sql_date_time_functions_test.cpp b/modules/platforms/cpp/odbc-test/src/sql_date_time_functions_test.cpp new file mode 100644 index 0000000..f89cc3d --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/sql_date_time_functions_test.cpp @@ -0,0 +1,213 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include + +#include "sql_test_suite_fixture.h" + +using namespace ignite; + +using namespace boost::unit_test; + +BOOST_FIXTURE_TEST_SUITE(SqlDateTimeFunctionTestSuite, ignite::SqlTestSuiteFixture) + +BOOST_AUTO_TEST_CASE(TestCurrentDate) +{ + CheckSingleResult("SELECT {fn CURRENT_DATE()}"); +} + +BOOST_AUTO_TEST_CASE(TestCurdate) +{ + CheckSingleResult("SELECT {fn CURDATE()}"); +} + +BOOST_AUTO_TEST_CASE(TestCurrentTime) +{ + CheckSingleResult("SELECT {fn CURRENT_TIME()}"); +} + +BOOST_AUTO_TEST_CASE(TestCurtime) +{ + CheckSingleResult("SELECT {fn CURTIME()}"); +} + +BOOST_AUTO_TEST_CASE(TestCurrentTimestamp) +{ + CheckSingleResult("SELECT {fn CURRENT_TIMESTAMP()}"); +} + +BOOST_AUTO_TEST_CASE(TestDayname) +{ + TestType in; + + in.dateField = impl::binary::BinaryUtils::MakeDateGmt(2016, 8, 29); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn DAYNAME(dateField)} FROM TestType", "Monday"); +} + +BOOST_AUTO_TEST_CASE(TestDayofmonth) +{ + TestType in; + + in.dateField = impl::binary::BinaryUtils::MakeDateGmt(2016, 8, 29); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn DAYOFMONTH(dateField)} FROM TestType", 29); + CheckSingleResult("SELECT {fn DAY_OF_MONTH(dateField)} FROM TestType", 29); +} + +BOOST_AUTO_TEST_CASE(TestDayofweek) +{ + TestType in; + + in.dateField = impl::binary::BinaryUtils::MakeDateGmt(2016, 8, 29); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn DAYOFWEEK(dateField)} FROM TestType", 2); + CheckSingleResult("SELECT {fn DAY_OF_WEEK(dateField)} FROM TestType", 2); +} + +BOOST_AUTO_TEST_CASE(TestDayofyear) +{ + TestType in; + + in.dateField = impl::binary::BinaryUtils::MakeDateGmt(2016, 8, 29); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn DAYOFYEAR(dateField)} FROM TestType", 242); + CheckSingleResult("SELECT {fn DAY_OF_YEAR(dateField)} FROM TestType", 242); +} + +BOOST_AUTO_TEST_CASE(TestExtract) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn EXTRACT(YEAR FROM timestampField)} FROM TestType", 2016); + CheckSingleResult("SELECT {fn EXTRACT(MONTH FROM timestampField)} FROM TestType", 2); + CheckSingleResult("SELECT {fn EXTRACT(DAY FROM timestampField)} FROM TestType", 24); + CheckSingleResult("SELECT {fn EXTRACT(HOUR FROM timestampField)} FROM TestType", 13); + CheckSingleResult("SELECT {fn EXTRACT(MINUTE FROM timestampField)} FROM TestType", 45); + CheckSingleResult("SELECT {fn EXTRACT(SECOND FROM timestampField)} FROM TestType", 23); +} + +BOOST_AUTO_TEST_CASE(TestHour) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn HOUR(timestampField)} FROM TestType", 13); +} + +BOOST_AUTO_TEST_CASE(TestMinute) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn MINUTE(timestampField)} FROM TestType", 45); +} + +BOOST_AUTO_TEST_CASE(TestMonth) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn MONTH(timestampField)} FROM TestType", 2); +} + +BOOST_AUTO_TEST_CASE(TestMonthname) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn MONTHNAME(timestampField)} FROM TestType", "February"); +} + +BOOST_AUTO_TEST_CASE(TestNow) +{ + CheckSingleResult("SELECT {fn NOW()}"); +} + +BOOST_AUTO_TEST_CASE(TestQuarter) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn QUARTER(timestampField)} FROM TestType", 1); +} + +BOOST_AUTO_TEST_CASE(TestSecond) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn SECOND(timestampField)} FROM TestType", 23); +} + +BOOST_AUTO_TEST_CASE(TestWeek) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn WEEK(timestampField)} FROM TestType", 9); +} + +BOOST_AUTO_TEST_CASE(TestYear) +{ + TestType in; + + in.timestampField = impl::binary::BinaryUtils::MakeTimestampGmt(2016, 2, 24, 13, 45, 23, 580695103); + + testCache.Put(1, in); + + CheckSingleResult("SELECT {fn YEAR(timestampField)} FROM TestType", 2016); +} + +BOOST_AUTO_TEST_SUITE_END() http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc-test/src/sql_test_suite_fixture.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/sql_test_suite_fixture.cpp b/modules/platforms/cpp/odbc-test/src/sql_test_suite_fixture.cpp index 657b854..e9a8fc5 100644 --- a/modules/platforms/cpp/odbc-test/src/sql_test_suite_fixture.cpp +++ b/modules/platforms/cpp/odbc-test/src/sql_test_suite_fixture.cpp @@ -34,6 +34,7 @@ namespace ignite cfg.jvmOpts.push_back("-Djava.compiler=NONE"); cfg.jvmOpts.push_back("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"); cfg.jvmOpts.push_back("-XX:+HeapDumpOnOutOfMemoryError"); + cfg.jvmOpts.push_back("-Duser.timezone=GMT"); #ifdef IGNITE_TESTS_32 cfg.jvmInitMem = 256; @@ -268,4 +269,20 @@ namespace ignite CheckSingleResult0(request, SQL_C_DOUBLE, &res, 0, 0); } + + template<> + void SqlTestSuiteFixture::CheckSingleResult(const char* request) + { + SQL_DATE_STRUCT res; + + CheckSingleResult0(request, SQL_C_DATE, &res, 0, 0); + } + + template<> + void SqlTestSuiteFixture::CheckSingleResult(const char* request) + { + SQL_TIMESTAMP_STRUCT res; + + CheckSingleResult0(request, SQL_C_TIMESTAMP, &res, 0, 0); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc/src/column.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/src/column.cpp b/modules/platforms/cpp/odbc/src/column.cpp index ec779ac..b076a12 100644 --- a/modules/platforms/cpp/odbc/src/column.cpp +++ b/modules/platforms/cpp/odbc/src/column.cpp @@ -58,7 +58,7 @@ namespace * complex type. * @return Column type header. */ - int8_t ReadColumnHeader(ignite::impl::interop::InteropInputStream& stream) + int8_t ReadColumnHeader(InteropInputStream& stream) { using namespace ignite::impl::binary; @@ -130,10 +130,10 @@ namespace ignite // No-op. } - Column::Column(ignite::impl::binary::BinaryReaderImpl& reader) : + Column::Column(BinaryReaderImpl& reader) : type(0), startPos(-1), endPos(-1), offset(0), size(0) { - ignite::impl::interop::InteropInputStream* stream = reader.GetStream(); + InteropInputStream* stream = reader.GetStream(); if (!stream) return; @@ -294,12 +294,8 @@ namespace ignite size = sizeTmp; } - SqlResult Column::ReadToBuffer(ignite::impl::binary::BinaryReaderImpl& reader, - app::ApplicationDataBuffer& dataBuf) + SqlResult Column::ReadToBuffer(BinaryReaderImpl& reader, app::ApplicationDataBuffer& dataBuf) { - using namespace ignite::impl::binary; - using namespace ignite::impl::interop; - if (!IsValid()) return SQL_RESULT_ERROR; @@ -310,7 +306,7 @@ namespace ignite return SQL_RESULT_NO_DATA; } - ignite::impl::interop::InteropInputStream* stream = reader.GetStream(); + InteropInputStream* stream = reader.GetStream(); if (!stream) return SQL_RESULT_ERROR; http://git-wip-us.apache.org/repos/asf/ignite/blob/a7609187/modules/platforms/cpp/odbc/src/config/connection_info.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/src/config/connection_info.cpp b/modules/platforms/cpp/odbc/src/config/connection_info.cpp index ca8d1a0..ee2c22b 100644 --- a/modules/platforms/cpp/odbc/src/config/connection_info.cpp +++ b/modules/platforms/cpp/odbc/src/config/connection_info.cpp @@ -254,7 +254,11 @@ namespace ignite #ifdef SQL_TIMEDATE_FUNCTIONS // Bitmask enumerating the scalar date and time functions supported // by the driver and associated data source. - intParams[SQL_TIMEDATE_FUNCTIONS] = 0; + intParams[SQL_TIMEDATE_FUNCTIONS] = SQL_FN_TD_CURRENT_DATE | SQL_FN_TD_CURRENT_TIME | + SQL_FN_TD_CURRENT_TIMESTAMP | SQL_FN_TD_CURDATE | SQL_FN_TD_CURTIME | SQL_FN_TD_DAYNAME | + SQL_FN_TD_DAYOFMONTH | SQL_FN_TD_DAYOFWEEK | SQL_FN_TD_DAYOFYEAR | SQL_FN_TD_EXTRACT | + SQL_FN_TD_HOUR | SQL_FN_TD_MINUTE | SQL_FN_TD_MONTH | SQL_FN_TD_MONTHNAME | SQL_FN_TD_NOW | + SQL_FN_TD_QUARTER | SQL_FN_TD_SECOND | SQL_FN_TD_WEEK | SQL_FN_TD_YEAR; #endif // SQL_TIMEDATE_FUNCTIONS #ifdef SQL_TIMEDATE_ADD_INTERVALS @@ -272,15 +276,7 @@ namespace ignite #ifdef SQL_DATETIME_LITERALS // Bitmask enumerating the SQL-92 datetime literals supported by // the data source. - intParams[SQL_DATETIME_LITERALS] = SQL_DL_SQL92_INTERVAL_HOUR | - SQL_DL_SQL92_DATE | SQL_DL_SQL92_INTERVAL_MINUTE_TO_SECOND | - SQL_DL_SQL92_TIME | SQL_DL_SQL92_INTERVAL_HOUR_TO_SECOND | - SQL_DL_SQL92_TIMESTAMP | SQL_DL_SQL92_INTERVAL_HOUR_TO_MINUTE | - SQL_DL_SQL92_INTERVAL_YEAR | SQL_DL_SQL92_INTERVAL_DAY_TO_SECOND | - SQL_DL_SQL92_INTERVAL_MONTH | SQL_DL_SQL92_INTERVAL_DAY_TO_HOUR | - SQL_DL_SQL92_INTERVAL_DAY | SQL_DL_SQL92_INTERVAL_DAY_TO_MINUTE | - SQL_DL_SQL92_INTERVAL_MINUTE | SQL_DL_SQL92_INTERVAL_SECOND | - SQL_DL_SQL92_INTERVAL_YEAR_TO_MONTH; + intParams[SQL_DATETIME_LITERALS] = SQL_DL_SQL92_DATE | SQL_DL_SQL92_TIME | SQL_DL_SQL92_TIMESTAMP; #endif // SQL_DATETIME_LITERALS #ifdef SQL_SYSTEM_FUNCTIONS