Zoltan Borok-Nagy has posted comments on this change. ( http://gerrit.cloudera.org:8080/11450 )
Change subject: IMPALA-7492: Add support for DATE text parser/formatter ...................................................................... Patch Set 1: (12 comments) http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/benchmarks/convert-timestamp-benchmark.cc File be/src/benchmarks/convert-timestamp-benchmark.cc: http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/benchmarks/convert-timestamp-benchmark.cc@152 PS1, Line 152: 19 nit: shouldn't it be 20? Maybe you could add a Reset function that only takes a const char*, and uses strlen() inside. http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.h File be/src/runtime/date-parse-util.h: http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.h@26 PS1, Line 26: namespace dtp = datetime_parse_util; nit: It is against the google style guide: "Do not use Namespace aliases at namespace scope in header files except in explicitly marked internal-only namespaces" https://google.github.io/styleguide/cppguide.html#Namespaces http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.h@59 PS1, Line 59: /// Returns the realigned year value for dt_result.year. This function should be called : /// only if dt_result.realign_year is true. Please explain what is a realigned year. You can re-use the original comment from timestamp-parse-util.h http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.cc File be/src/runtime/date-parse-util.cc: http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.cc@61 PS1, Line 61: NULL nit: nullptr http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.cc@71 PS1, Line 71: if (!date->IsValid()) return false; : : return true; nit: return date->IsValid(); http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.cc@132 PS1, Line 132: DateTimeFormatContext lazy_ctx; : lazy_ctx.Reset(str, trimmed_len); nit: could be a one-liner with a constructor call. http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.cc@147 PS1, Line 147: NULL nit: nullptr http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-parse-util.cc@155 PS1, Line 155: NULL nit: nullptr http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-test.cc File be/src/runtime/date-test.cc: http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-test.cc@140 PS1, Line 140: for (int i = 0; i < toks_len; ++i) { : fmt.append((*toks)[i].fmt); : if ((*toks)[i].str != nullptr) { : val.append(string((*toks)[i].str)); : } else { : val.append(lexical_cast<string>((*toks)[i].val)); : } : } : string fmt_val = "Format: " + fmt + ", Val: " + val; : DateTimeFormatContext dt_ctx(fmt.c_str(), fmt.length()); : ASSERT_TRUE(ParseFormatTokens(&dt_ctx, false)) << fmt_val; : DateValue dv = DateValue::Parse(val.c_str(), val.length(), dt_ctx); : ValidateDate(dv, year, month, day, fmt_val); : int buff_len = dt_ctx.fmt_out_len + 1; : char buff[buff_len]; : int actual_len = dv.Format(dt_ctx, buff_len, buff); : EXPECT_GT(actual_len, 0) << fmt_val; : EXPECT_LE(actual_len, dt_ctx.fmt_len) << fmt_val; : string buff_str(buff); : EXPECT_EQ(buff_str, val) << fmt_val << " " << buff_str; : fmt.clear(); : val.clear(); : } : // Validate we can parse date with separators : { : for (const char* separator = SEPARATORS; *separator != 0; ++separator) { : for (int i = 0; i < toks_len; ++i) { : fmt.append((*toks)[i].fmt); : if (i + 1 < toks_len) fmt.push_back(*separator); : if ((*toks)[i].str != nullptr) { : val.append(string((*toks)[i].str)); : } else { : val.append(lexical_cast<string>((*toks)[i].val)); : } : if (i + 1 < toks_len) val.push_back(*separator); : } : string fmt_val = "Format: " + fmt + ", Val: " + val; : DateTimeFormatContext dt_ctx(fmt.c_str(), fmt.length()); : ASSERT_TRUE(ParseFormatTokens(&dt_ctx, false)) << fmt_val; : DateValue dv = DateValue::Parse(val.c_str(), val.length(), dt_ctx); : ValidateDate(dv, year, month, day, fmt_val); : int buff_len = dt_ctx.fmt_out_len + 1; : char buff[buff_len]; : int actual_len = dv.Format(dt_ctx, buff_len, buff); : EXPECT_GT(actual_len, 0) << fmt_val; : EXPECT_LE(actual_len, dt_ctx.fmt_len) << fmt_val; : string buff_str(buff); : EXPECT_EQ(buff_str, val) << fmt_val << " " << buff_str; : fmt.clear(); : val.clear(); : } nit: the common part could be moved to a function http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-value.h File be/src/runtime/date-value.h: http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/date-value.h@35 PS1, Line 35: 9999-01-01 Based on the tests and MAX_DAYS_SINCE_EPOCH maximum date is 9999-12-31 http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/timestamp-parse-util.h File be/src/runtime/timestamp-parse-util.h: http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/timestamp-parse-util.h@33 PS1, Line 33: namespace dtp = datetime_parse_util; nit: namespace aliases are not allowed in headers http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/timestamp-value.h File be/src/runtime/timestamp-value.h: http://gerrit.cloudera.org:8080/#/c/11450/1/be/src/runtime/timestamp-value.h@44 PS1, Line 44: namespace dtp = datetime_parse_util; nit: namespace aliases aren't allowed in headers -- To view, visit http://gerrit.cloudera.org:8080/11450 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-Project: Impala-ASF Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: I1eec00f22502c4c67c6807c4b51384419ea8b831 Gerrit-Change-Number: 11450 Gerrit-PatchSet: 1 Gerrit-Owner: Attila Jeges <[email protected]> Gerrit-Reviewer: Csaba Ringhofer <[email protected]> Gerrit-Reviewer: Impala Public Jenkins <[email protected]> Gerrit-Reviewer: Tim Armstrong <[email protected]> Gerrit-Reviewer: Zoltan Borok-Nagy <[email protected]> Gerrit-Comment-Date: Mon, 17 Sep 2018 16:26:59 +0000 Gerrit-HasComments: Yes
