Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions be/src/runtime/runtime_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "runtime/workload_group/workload_group.h"
#include "util/debug_util.h"
#include "util/runtime_profile.h"
#include "util/timezone_utils.h"
#include "vec/runtime/vector_search_user_params.h"

namespace doris {
Expand Down Expand Up @@ -181,6 +182,10 @@ class RuntimeState {
// if possible, use timezone_obj() rather than timezone()
const std::string& timezone() const { return _timezone; }
const cctz::time_zone& timezone_obj() const { return _timezone_obj; }
void set_timezone(const std::string& timezone) {
_timezone = timezone;
TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj);
}
const std::string& lc_time_names() const { return _lc_time_names; }
const std::string& user() const { return _user; }
const TUniqueId& query_id() const { return _query_id; }
Expand Down
4 changes: 4 additions & 0 deletions be/src/service/point_query_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ Status PointQueryExecutor::init(const PTabletKeyLookupRequest* request,
*_tablet->tablet_schema(), 1));
}
}
// Set timezone from request for functions like from_unixtime()
if (request->has_time_zone() && !request->time_zone().empty()) {
_reusable->runtime_state()->set_timezone(request->time_zone());
}
if (request->has_version() && request->version() >= 0) {
_version = request->version();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ private RowBatch getNextInternal(Status status, Backend backend) throws TExcepti
.setOutputExpr(shortCircuitQueryContext.serializedOutputExpr)
.setQueryOptions(shortCircuitQueryContext.serializedQueryOptions)
.setIsBinaryRow(ConnectContext.get().command == MysqlCommand.COM_STMT_EXECUTE);
// Set timezone for functions like from_unixtime
String timeZone = ConnectContext.get().getSessionVariable().getTimeZone();
if ("CST".equals(timeZone)) {
timeZone = "Asia/Shanghai";
}
requestBuilder.setTimeZone(timeZone);
if (snapshotVisibleVersions != null && !snapshotVisibleVersions.isEmpty()) {
requestBuilder.setVersion(snapshotVisibleVersions.get(0));
}
Expand Down
2 changes: 2 additions & 0 deletions gensrc/proto/internal_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ message PTabletKeyLookupRequest {
optional int64 version = 7;
// serilized from TQueryOptions
optional bytes query_options = 8;
// timezone string, e.g. "America/Mexico_City"
optional string time_zone = 9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we directly pass a whole TQueryGlobals?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTabletKeyLookupRequest is protobuf but TQueryGlobals is thrift

}

message PTabletKeyLookupResponse {
Expand Down
15 changes: 15 additions & 0 deletions regression-test/data/point_query_p0/test_point_query_timezone.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !full_scan --
job_001 2024-01-31 18:00:00.000000
job_002 2024-02-01 18:00:00.000000

-- !point_query --
job_001 2024-01-31 18:00:00.000000

-- !full_scan_tokyo --
job_001 2024-02-01 09:00:00.000000
job_002 2024-02-02 09:00:00.000000

-- !point_query_tokyo --
job_001 2024-02-01 09:00:00.000000

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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.

// Test point query timezone handling (cir_19478)
// Point queries on unique key tables with row store should respect
// session timezone for functions like from_unixtime()
suite("test_point_query_timezone") {
def tableName = "test_point_query_timezone_tbl"

sql """ DROP TABLE IF EXISTS ${tableName} """
sql """
CREATE TABLE ${tableName} (
`job_id` VARCHAR(50) NOT NULL,
`capture_time` BIGINT NOT NULL,
`event_time` BIGINT NULL
) ENGINE=OLAP
UNIQUE KEY(`job_id`, `capture_time`)
DISTRIBUTED BY HASH(`job_id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"store_row_column" = "true",
"enable_unique_key_merge_on_write" = "true"
)
"""

sql """ INSERT INTO ${tableName} VALUES ('job_001', 1706745600000, 1706745600000) """
sql """ INSERT INTO ${tableName} VALUES ('job_002', 1706832000000, 1706832000000) """

// Verify it's a short-circuit (point) query
explain {
sql("SELECT * FROM ${tableName} WHERE job_id = 'job_001' AND capture_time = 1706745600000")
contains "SHORT-CIRCUIT"
}

// Test with America/Mexico_City timezone (UTC-6)
// 1706745600 = 2024-02-01 00:00:00 UTC = 2024-01-31 18:00:00 Mexico_City
sql """ SET time_zone = 'America/Mexico_City' """

// Full table scan - should use session timezone
qt_full_scan """ SELECT job_id, from_unixtime(event_time/1000) AS t FROM ${tableName} ORDER BY job_id """

// Point query - should also use session timezone (this was the bug)
qt_point_query """ SELECT job_id, from_unixtime(event_time/1000) AS t FROM ${tableName} WHERE job_id = 'job_001' AND capture_time = 1706745600000 """

// Test with Asia/Tokyo timezone (UTC+9)
// 1706745600 = 2024-02-01 00:00:00 UTC = 2024-02-01 09:00:00 Tokyo
sql """ SET time_zone = 'Asia/Tokyo' """

qt_full_scan_tokyo """ SELECT job_id, from_unixtime(event_time/1000) AS t FROM ${tableName} ORDER BY job_id """

qt_point_query_tokyo """ SELECT job_id, from_unixtime(event_time/1000) AS t FROM ${tableName} WHERE job_id = 'job_001' AND capture_time = 1706745600000 """

// Reset timezone
sql """ SET time_zone = 'Asia/Shanghai' """

sql """ DROP TABLE IF EXISTS ${tableName} """
}
Loading