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
8 changes: 4 additions & 4 deletions be/src/exprs/timestamp_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ StringVal TimestampFunctions::from_unix(
}

IntVal TimestampFunctions::to_unix(FunctionContext* context) {
return IntVal(context->impl()->state()->timestamp() / 1000);
return IntVal(context->impl()->state()->timestamp_ms() / 1000);
}

IntVal TimestampFunctions::to_unix(
Expand Down Expand Up @@ -462,7 +462,7 @@ IntVal TimestampFunctions::to_unix(

DateTimeVal TimestampFunctions::utc_timestamp(FunctionContext* context) {
DateTimeValue dtv;
if (!dtv.from_unixtime(context->impl()->state()->timestamp() / 1000, "+00:00")) {
if (!dtv.from_unixtime(context->impl()->state()->timestamp_ms() / 1000, "+00:00")) {
return DateTimeVal::null();
}

Expand All @@ -473,7 +473,7 @@ DateTimeVal TimestampFunctions::utc_timestamp(FunctionContext* context) {

DateTimeVal TimestampFunctions::now(FunctionContext* context) {
DateTimeValue dtv;
if (!dtv.from_unixtime(context->impl()->state()->timestamp() / 1000,
if (!dtv.from_unixtime(context->impl()->state()->timestamp_ms() / 1000,
context->impl()->state()->timezone())) {
return DateTimeVal::null();
}
Expand All @@ -485,7 +485,7 @@ DateTimeVal TimestampFunctions::now(FunctionContext* context) {

DoubleVal TimestampFunctions::curtime(FunctionContext* context) {
DateTimeValue dtv;
if (!dtv.from_unixtime(context->impl()->state()->timestamp() / 1000,
if (!dtv.from_unixtime(context->impl()->state()->timestamp_ms() / 1000,
context->impl()->state()->timezone())) {
return DoubleVal::null();
}
Expand Down
22 changes: 20 additions & 2 deletions be/src/runtime/runtime_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,20 @@ RuntimeState::RuntimeState(const TQueryGlobals& query_globals)
_profile(_obj_pool.get(), "<unnamed>"),
_per_fragment_instance_idx(0) {
_query_options.batch_size = DEFAULT_BATCH_SIZE;
_timestamp = atol(query_globals.now_string.c_str());
if (query_globals.__isset.time_zone) {
_timezone = query_globals.time_zone;
_timestamp_ms = query_globals.timestamp_ms;
} else if (!query_globals.now_string.empty()) {
_timezone = TimezoneDatabase::default_time_zone;
DateTimeValue dt;
dt.from_date_str(query_globals.now_string.c_str(), query_globals.now_string.size());
int64_t timestamp;
dt.unix_timestamp(&timestamp, _timezone);
_timestamp_ms = timestamp * 1000;
} else {
//Unit test may set into here
_timezone = TimezoneDatabase::default_time_zone;
_timestamp_ms = 0;
}
}

Expand Down Expand Up @@ -169,11 +178,20 @@ Status RuntimeState::init(
const TQueryGlobals& query_globals, ExecEnv* exec_env) {
_fragment_instance_id = fragment_instance_id;
_query_options = query_options;
_timestamp = atol(query_globals.now_string.c_str());
if (query_globals.__isset.time_zone) {
_timezone = query_globals.time_zone;
_timestamp_ms = query_globals.timestamp_ms;
} else if (!query_globals.now_string.empty()) {
_timezone = TimezoneDatabase::default_time_zone;
DateTimeValue dt;
dt.from_date_str(query_globals.now_string.c_str(), query_globals.now_string.size());
int64_t timestamp;
dt.unix_timestamp(&timestamp, _timezone);
_timestamp_ms = timestamp * 1000;
} else {
//Unit test may set into here
_timezone = TimezoneDatabase::default_time_zone;
_timestamp_ms = 0;
}
_exec_env = exec_env;

Expand Down
8 changes: 4 additions & 4 deletions be/src/runtime/runtime_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class RuntimeState {
int num_scanner_threads() const {
return _query_options.num_scanner_threads;
}
int64_t timestamp() const {
return _timestamp;
int64_t timestamp_ms() const {
return _timestamp_ms;
}
const std::string& timezone() const {
return _timezone;
Expand Down Expand Up @@ -536,8 +536,8 @@ class RuntimeState {
// Username of user that is executing the query to which this RuntimeState belongs.
std::string _user;

//Query-global timestamp
int64_t _timestamp;
//Query-global timestamp_ms
int64_t _timestamp_ms;
std::string _timezone;

TUniqueId _query_id;
Expand Down
3 changes: 2 additions & 1 deletion be/test/exprs/timestamp_functions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class TimestampFunctionsTest : public testing::Test {
TimezoneDatabase::init();

TQueryGlobals globals;
globals.__set_now_string("1565080737805");
globals.__set_now_string("2019-08-06 01:38:57");
globals.__set_timestamp_ms(1565080737805);
globals.__set_time_zone("America/Los_Angeles");
state = new RuntimeState(globals);
utils = new FunctionUtils(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ LOAD LABEL db1.label1
SET
(
id=tmp_c2,
name=tmp_c1)
name=tmp_c1
),
DATA INFILE("hdfs://abc.com:8888/user/palo/test/ml/file2")
INTO TABLE tbl2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Description

��õ�ǰ��ʱ�䣬��TIME���ͷ���
获得当前的时间,以TIME类型返回

## Examples

Expand Down
10 changes: 8 additions & 2 deletions fe/src/main/java/org/apache/doris/qe/Coordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
import org.apache.logging.log4j.Logger;
import org.apache.thrift.TException;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -105,6 +107,8 @@
public class Coordinator {
private static final Logger LOG = LogManager.getLogger(Coordinator.class);

private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

private static String localIP = FrontendOptions.getLocalHostAddress();

// Overall status of the entire query; set to the first reported fragment error
Expand Down Expand Up @@ -190,7 +194,8 @@ public Coordinator(ConnectContext context, Analyzer analyzer, Planner planner) {
this.descTable = analyzer.getDescTbl().toThrift();
this.returnedAllResults = false;
this.queryOptions = context.getSessionVariable().toThrift();
this.queryGlobals.setNow_string(String.valueOf(new Date().getTime()));
this.queryGlobals.setNow_string(DATE_FORMAT.format(new Date()));
this.queryGlobals.setTimestamp_ms(new Date().getTime());
if (context.getSessionVariable().getTimeZone().equals("CST")) {
this.queryGlobals.setTime_zone(TimeUtils.DEFAULT_TIME_ZONE);
} else {
Expand All @@ -215,7 +220,8 @@ public Coordinator(Long jobId, TUniqueId queryId, DescriptorTable descTable,
this.fragments = fragments;
this.scanNodes = scanNodes;
this.queryOptions = new TQueryOptions();
this.queryGlobals.setNow_string(String.valueOf(new Date().getTime()));
this.queryGlobals.setNow_string(DATE_FORMAT.format(new Date()));
this.queryGlobals.setTimestamp_ms(new Date().getTime());
this.queryGlobals.setTime_zone(TimeUtils.DEFAULT_TIME_ZONE);
this.tResourceInfo = new TResourceInfo("", "");
this.needReport = true;
Expand Down
10 changes: 9 additions & 1 deletion gensrc/thrift/PaloInternalService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,16 @@ struct TPlanFragmentExecParams {
// Global query parameters assigned by the coordinator.
struct TQueryGlobals {
// String containing a timestamp set as the current time.
// Format is yyyy-MM-dd HH:mm:ss
1: required string now_string
2: optional string time_zone

// To support timezone in Doris. timestamp_ms is the millisecond uinix timestamp for
// this query to calculate time zone relative function
2: optional i64 timestamp_ms

// time_zone is the timezone this query used.
// If this value is set, BE will ignore now_string
3: optional string time_zone
}


Expand Down