Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
gdliu3 committed Jul 28, 2024
1 parent ba0eb23 commit 5b201d1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
11 changes: 8 additions & 3 deletions be/src/runtime/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ struct TypeDescriptor {
TypeDescriptor() : type(INVALID_TYPE), len(-1), precision(-1), scale(-1) {}

// explicit TypeDescriptor(PrimitiveType type) :
TypeDescriptor(PrimitiveType type) : type(type), len(-1), precision(-1), scale(-1) {
TypeDescriptor(PrimitiveType type, int64_t scale = -1)
: type(type), len(-1), precision(-1), scale(scale) {
if (type == TYPE_DECIMALV2) {
precision = 27;
scale = 9;
if (scale == -1) {
scale = 9;
}
} else if (type == TYPE_DATETIMEV2) {
precision = 18;
scale = 6;
if (scale == -1) {
scale = 6;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions be/src/util/arrow/row_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ Status convert_to_arrow_type(const TypeDescriptor& type, std::shared_ptr<arrow::
break;
case TYPE_DATETIMEV2:
if (type.scale > 3) {
*result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MICRO);
*result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MICRO, "UTC");
} else if (type.scale > 0) {
*result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MILLI);
*result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MILLI, "UTC");
} else {
*result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::SECOND);
*result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::SECOND, "UTC");
}
break;
case TYPE_DECIMALV2:
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/data_types/data_type_time_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DataTypeDateTimeV2 final : public DataTypeNumberBase<UInt64> {
DataTypeDateTimeV2(const DataTypeDateTimeV2& rhs) : _scale(rhs._scale) {}
TypeIndex get_type_id() const override { return TypeIndex::DateTimeV2; }
TypeDescriptor get_type_as_type_descriptor() const override {
return TypeDescriptor(TYPE_DATETIMEV2);
return TypeDescriptor(TYPE_DATETIMEV2, _scale);
}

doris::FieldType get_storage_field_type() const override {
Expand Down
6 changes: 4 additions & 2 deletions be/src/vec/runtime/vdatetime_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3267,14 +3267,16 @@ bool DateV2Value<T>::unix_timestamp(int64_t* timestamp, const cctz::time_zone& c
date_v2_value_.day_, date_v2_value_.hour_,
date_v2_value_.minute_, date_v2_value_.second_),
ctz);
*timestamp = tp.time_since_epoch().count();
*timestamp =
std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch()).count();
return true;
} else {
const auto tp =
cctz::convert(cctz::civil_second(date_v2_value_.year_, date_v2_value_.month_,
date_v2_value_.day_, 0, 0, 0),
ctz);
*timestamp = tp.time_since_epoch().count();
*timestamp =
std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch()).count();
return true;
}
}
Expand Down
5 changes: 5 additions & 0 deletions regression-test/data/arrow_flight_sql_p0/test_select.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
-- !arrow_flight_sql --
777 4

-- !arrow_flight_sql_datetime --
333 plsql333 2024-07-21 04:00:00.123456 2024-07-21 04:00:00.0
222 plsql222 2024-07-20 04:00:00.123456 2024-07-20 04:00:00.0
111 plsql111 2024-07-19 04:00:00.123456 2024-07-19 04:00:00.0

15 changes: 14 additions & 1 deletion regression-test/suites/arrow_flight_sql_p0/test_select.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ suite("test_select", "arrow_flight_sql") {
sql """INSERT INTO ${tableName} VALUES(222, "plsql222")"""
sql """INSERT INTO ${tableName} VALUES(333, "plsql333")"""
sql """INSERT INTO ${tableName} VALUES(111, "plsql333")"""

qt_arrow_flight_sql "select sum(id) as a, count(1) as b from ${tableName}"

tableName = "test_select_datetime"
sql "DROP TABLE IF EXISTS ${tableName}"
sql """
create table ${tableName} (id int, name varchar(20), f_datetime_p datetime(6), f_datetime datetime) DUPLICATE key(`id`) distributed by hash (`id`) buckets 4
properties ("replication_num"="1");
"""
sql """INSERT INTO ${tableName} VALUES(111, "plsql111","2024-07-19 12:00:00.123456","2024-07-19 12:00:00")"""
sql """INSERT INTO ${tableName} VALUES(222, "plsql222","2024-07-20 12:00:00.123456","2024-07-20 12:00:00")"""
sql """INSERT INTO ${tableName} VALUES(333, "plsql333","2024-07-21 12:00:00.123456","2024-07-21 12:00:00")"""

qt_arrow_flight_sql_datetime "select * from ${tableName} order by id desc"

}

0 comments on commit 5b201d1

Please sign in to comment.