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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7dc2c22  [tools] limit auto-generated values for DATE columns
7dc2c22 is described below

commit 7dc2c22c6bc88481fdd075507670d946cc4e6a91
Author: Alexey Serbin <[email protected]>
AuthorDate: Thu Jan 13 11:59:46 2022 -0800

    [tools] limit auto-generated values for DATE columns
    
    Prior to this patch, an attempt to run the `kudu perf loadgen` CLI tool
    on an already existing table having at least one DATE type column would
    result in an error like below:
    
      $ kudu perf loadgen 127.0.0.1:9876 --table_name=test --use_upsert
      Runtime error: Invalid argument: value 2932903 out of range for date 
column 'date_type'
    
    With this patch, the `kudu perf loadgen` tool now passes with no error
    in such case.
    
    Change-Id: Id2c3b5acef79442b75386c7263e8d0e772a07a70
    Reviewed-on: http://gerrit.cloudera.org:8080/18147
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Andrew Wong <[email protected]>
---
 src/kudu/tools/tool_action_perf.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/kudu/tools/tool_action_perf.cc 
b/src/kudu/tools/tool_action_perf.cc
index ace1c63..9c11119 100644
--- a/src/kudu/tools/tool_action_perf.cc
+++ b/src/kudu/tools/tool_action_perf.cc
@@ -546,7 +546,14 @@ Status GenerateRowData(Generator* key_gen, Generator* 
value_gen, KuduPartialRow*
         RETURN_NOT_OK(row->SetUnixTimeMicros(idx, gen->Next<int64_t>()));
         break;
       case DATE:
-        RETURN_NOT_OK(row->SetDate(idx, gen->Next<int32_t>()));
+        {
+          // The DATE type has limits on the min and max value dictated by the
+          // representation such as 0001-01-01 and 9999-12-31 correspondingly.
+          int32_t val = gen->Next<int32_t>();
+          val = std::max(val, *DataTypeTraits<DATE>::min_value());
+          val = std::min(val, *DataTypeTraits<DATE>::max_value());
+          RETURN_NOT_OK(row->SetDate(idx, val));
+        }
         break;
       case FLOAT:
         RETURN_NOT_OK(row->SetFloat(idx, gen->Next<float>()));

Reply via email to