morningman commented on code in PR #60557: URL: https://github.com/apache/doris/pull/60557#discussion_r2780494246
########## regression-test/suites/external_table_p0/remote_doris/test_insert_remote_doris_as_olap_table_select.groovy: ########## @@ -0,0 +1,455 @@ +// 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. + +suite("test_insert_remote_doris_as_olap_table_select", "p0,external,doris,external_docker,external_docker_doris") { + String remote_doris_host = context.config.otherConfigs.get("extArrowFlightSqlHost") + String remote_doris_arrow_port = context.config.otherConfigs.get("extArrowFlightSqlPort") + String remote_doris_http_port = context.config.otherConfigs.get("extArrowFlightHttpPort") + String remote_doris_user = context.config.otherConfigs.get("extArrowFlightSqlUser") + String remote_doris_psw = context.config.otherConfigs.get("extArrowFlightSqlPassword") + String remote_doris_thrift_port = context.config.otherConfigs.get("extFeThriftPort") + + def showres = sql "show frontends"; + remote_doris_arrow_port = showres[0][6] + remote_doris_http_port = showres[0][3] + remote_doris_thrift_port = showres[0][5] + log.info("show frontends log = ${showres}, arrow: ${remote_doris_arrow_port}, http: ${remote_doris_http_port}, thrift: ${remote_doris_thrift_port}") + + def showres2 = sql "show backends"; + log.info("show backends log = ${showres2}") + + def db_name = "test_insert_remote_doris_as_olap_table_select_db" + def catalog_name = "test_insert_remote_doris_as_olap_table_select_catalog" + + sql """DROP DATABASE IF EXISTS ${db_name}""" + + sql """CREATE DATABASE IF NOT EXISTS ${db_name}""" + + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_select_t` ( + `id` datetime(3) NOT NULL, + `c_boolean` boolean NULL, + `c_tinyint` tinyint NULL, + `c_smallint` smallint NULL, + `c_int` int NULL, + `c_bigint` bigint NULL, + `c_largeint` largeint NULL, + `c_float` float NULL, + `c_double` double NULL, + `c_decimal9` decimal(9,0) NULL, + `c_decimal18` decimal(18,0) NULL, + `c_decimal32` decimal(32,0) NULL, + `c_date` date NULL, + `c_datetime` datetime NULL, + `c_char` char(1) NULL, + `c_varchar` varchar(65533) NULL, + `c_string` text NULL, + `c_array_s` array<text> NULL, + `c_map` MAP<STRING, INT> NULL, + `c_struct` STRUCT<f1:INT,f2:FLOAT,f3:STRING> NULL, + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + DROP CATALOG IF EXISTS `${catalog_name}` + """ + + + sql """ + CREATE CATALOG `${catalog_name}` PROPERTIES ( + 'type' = 'doris', + 'fe_http_hosts' = 'http://${remote_doris_host}:${remote_doris_http_port}', + 'fe_arrow_hosts' = '${remote_doris_host}:${remote_doris_arrow_port}', + 'fe_thrift_hosts' = '${remote_doris_host}:${remote_doris_thrift_port}', + 'user' = '${remote_doris_user}', + 'password' = '${remote_doris_psw}', + 'use_arrow_flight' = 'false' + ); + """ + + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 01:00:00.000', true, -128, -32768, -2147483648, -9223372036854775808, -1234567890123456790, -123.456, -123456.789, -123457, -123456789012346, -1234567890123456789012345678, '1970-01-01', '0000-01-01 00:00:00', 'A', 'Hello', 'Hello, Doris!', '["apple", "banana", "orange"]', {"Emily":101,"age":25} , {11, 3.14, "Emily"}) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 02:00:00.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 03:00:00.000', false, 127, 32767, 2147483647, 9223372036854775807, 1234567890123456789, 123.456, 123456.789, 123457, 123456789012346, 1234567890123456789012345678, '9999-12-31', '9999-12-31 23:59:59', '', '', '', [], {}, {11, 3.14, "Emily"}) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 04:00:00.000', true, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '2023-10-01', '2023-10-01 12:34:56', 'A', 'Hello', 'Hello, Doris!', '["apple", "banana", "orange"]', {"Emily":101,"age":25} , {11, 3.14, "Emily"}); + """ + + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_select_t2` ( + `id` datetime(3) NOT NULL, + `a_boolean` array<boolean> NULL, + `a_tinyint` array<tinyint> NULL, + `a_smallint` array<smallint> NULL, + `a_int` array<int> NULL, + `a_bigint` array<bigint> NULL, + `a_largeint` array<largeint> NULL, + `a_float` array<float> NULL, + `a_double` array<double> NULL, + `a_decimal9` array<decimal(9,0)> NULL, + `a_decimal18` array<decimal(18,0)> NULL, + `a_decimal32` array<decimal(32,0)> NULL, + `a_date` array<date> NULL, + `a_datetime` array<datetime> NULL, + `a_char` array<char(1)> NULL, + `a_varchar` array<varchar(65533)> NULL, + `a_string` array<text> NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 01:00:00.000', [true], [-128], [-32768], [-2147483648], [-9223372036854775808], [-1234567890123456790], [-123.456], [-123456.789], [-123457], [-123456789012346], [-1234567890123456789012345678], ['0000-01-01'], ['0000-01-01 00:00:00'], ['A'], ['Hello'], ['Hello, Doris!']) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 02:00:00.000', [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL]) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 03:00:00.000', [false], [127], [32767], [2147483647], [9223372036854775807], [1234567890123456789], [123.456], [123456.789], [123457], [123456789012346], [1234567890123456789012345678], ['9999-12-31'], ['9999-12-31 23:59:59'], [''], [''], ['']) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 04:00:00.000', [true], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], ['2023-10-01'], ['2023-10-01 12:34:56'], ['A'], ['Hello'], ['Hello, Doris!']); + """ + + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_select_t3` ( + `id` datetime NOT NULL, + `datetime_0` datetime(0) NULL, + `datetime_1` datetime(1) NULL, + `datetime_3` datetime(2) NULL, + `datetime_4` datetime(3) NULL, + `datetime_5` datetime(4) NULL, + `datetime_6` datetime(5) NULL, + `datetime_7` datetime(6) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` values('2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111'); + """ + + + + qt_sql """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` order by id + """ + + qt_sql """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` order by id + """ + + qt_sql """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` order by id + """ + + // test select after insert also get correct data, it seems we can newly partition version + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` values('2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111'); + """ + qt_query_after_insert """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` order by id + """ + + // test insert command + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_insert` ( + `id` datetime(3) NOT NULL, + `c_boolean` boolean NULL, + `c_tinyint` tinyint NULL, + `c_smallint` smallint NULL, + `c_int` int NULL, + `c_bigint` bigint NULL, + `c_largeint` largeint NULL, + `c_float` float NULL, + `c_double` double NULL, + `c_decimal9` decimal(9,0) NULL, + `c_decimal18` decimal(18,0) NULL, + `c_decimal32` decimal(32,0) NULL, + `c_date` date NULL, + `c_datetime` datetime NULL, + `c_char` char(1) NULL, + `c_varchar` varchar(65533) NULL, + `c_string` text NULL, + `c_array_s` array<text> NULL, + `c_map` MAP<STRING, INT> NULL, + `c_struct` STRUCT<f1:INT,f2:FLOAT,f3:STRING> NULL, + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + // test insert into + explain { + sql("insert into `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t`") + contains("VOlapScanNode") + } + sql """ + insert into `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` + """ + qt_after_insert_cmd """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` order by id + """ + // test insert overwrite + explain { + sql("insert OVERWRITE table `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t`") + contains("VOlapScanNode") + } + sql """ + insert OVERWRITE table `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` Review Comment: And why we set these 2 variables? ########## gensrc/thrift/FrontendService.thrift: ########## @@ -1662,13 +1662,178 @@ struct TGetOlapTableMetaRequest { 5: required i64 table_id 6: optional i32 version // todo serialize according to the version 7: optional list<TPartitionMeta> partitions // client owned partition meta + 8: optional list<TPartitionMeta> temp_partitions // client owned partition meta } struct TGetOlapTableMetaResult { 1: required Status.TStatus status 2: required binary table_meta 3: optional list<binary> updated_partitions 4: optional list<i64> removed_partitions + 5: optional list<binary> updated_temp_partitions + 6: optional list<i64> removed_temp_partitions +} + +// Remote transaction request and Result definitions for cross-cluster export. +// These structs are used by beginRemoteTxn/commitRemoteTxn/abortRemoteTxn RPCs. +struct TBeginRemoteTxnRequest { + 1: required string user Review Comment: always use `optional` for all fields ########## regression-test/suites/external_table_p0/remote_doris/test_insert_remote_doris_as_olap_table_select.groovy: ########## @@ -0,0 +1,455 @@ +// 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. + +suite("test_insert_remote_doris_as_olap_table_select", "p0,external,doris,external_docker,external_docker_doris") { + String remote_doris_host = context.config.otherConfigs.get("extArrowFlightSqlHost") + String remote_doris_arrow_port = context.config.otherConfigs.get("extArrowFlightSqlPort") + String remote_doris_http_port = context.config.otherConfigs.get("extArrowFlightHttpPort") + String remote_doris_user = context.config.otherConfigs.get("extArrowFlightSqlUser") + String remote_doris_psw = context.config.otherConfigs.get("extArrowFlightSqlPassword") + String remote_doris_thrift_port = context.config.otherConfigs.get("extFeThriftPort") + + def showres = sql "show frontends"; + remote_doris_arrow_port = showres[0][6] + remote_doris_http_port = showres[0][3] + remote_doris_thrift_port = showres[0][5] + log.info("show frontends log = ${showres}, arrow: ${remote_doris_arrow_port}, http: ${remote_doris_http_port}, thrift: ${remote_doris_thrift_port}") + + def showres2 = sql "show backends"; + log.info("show backends log = ${showres2}") + + def db_name = "test_insert_remote_doris_as_olap_table_select_db" + def catalog_name = "test_insert_remote_doris_as_olap_table_select_catalog" + + sql """DROP DATABASE IF EXISTS ${db_name}""" + + sql """CREATE DATABASE IF NOT EXISTS ${db_name}""" + + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_select_t` ( + `id` datetime(3) NOT NULL, + `c_boolean` boolean NULL, + `c_tinyint` tinyint NULL, + `c_smallint` smallint NULL, + `c_int` int NULL, + `c_bigint` bigint NULL, + `c_largeint` largeint NULL, + `c_float` float NULL, + `c_double` double NULL, + `c_decimal9` decimal(9,0) NULL, + `c_decimal18` decimal(18,0) NULL, + `c_decimal32` decimal(32,0) NULL, + `c_date` date NULL, + `c_datetime` datetime NULL, + `c_char` char(1) NULL, + `c_varchar` varchar(65533) NULL, + `c_string` text NULL, + `c_array_s` array<text> NULL, + `c_map` MAP<STRING, INT> NULL, + `c_struct` STRUCT<f1:INT,f2:FLOAT,f3:STRING> NULL, + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + DROP CATALOG IF EXISTS `${catalog_name}` + """ + + + sql """ + CREATE CATALOG `${catalog_name}` PROPERTIES ( + 'type' = 'doris', + 'fe_http_hosts' = 'http://${remote_doris_host}:${remote_doris_http_port}', + 'fe_arrow_hosts' = '${remote_doris_host}:${remote_doris_arrow_port}', + 'fe_thrift_hosts' = '${remote_doris_host}:${remote_doris_thrift_port}', + 'user' = '${remote_doris_user}', + 'password' = '${remote_doris_psw}', + 'use_arrow_flight' = 'false' + ); + """ + + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 01:00:00.000', true, -128, -32768, -2147483648, -9223372036854775808, -1234567890123456790, -123.456, -123456.789, -123457, -123456789012346, -1234567890123456789012345678, '1970-01-01', '0000-01-01 00:00:00', 'A', 'Hello', 'Hello, Doris!', '["apple", "banana", "orange"]', {"Emily":101,"age":25} , {11, 3.14, "Emily"}) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 02:00:00.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 03:00:00.000', false, 127, 32767, 2147483647, 9223372036854775807, 1234567890123456789, 123.456, 123456.789, 123457, 123456789012346, 1234567890123456789012345678, '9999-12-31', '9999-12-31 23:59:59', '', '', '', [], {}, {11, 3.14, "Emily"}) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` values('2025-05-18 04:00:00.000', true, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '2023-10-01', '2023-10-01 12:34:56', 'A', 'Hello', 'Hello, Doris!', '["apple", "banana", "orange"]', {"Emily":101,"age":25} , {11, 3.14, "Emily"}); + """ + + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_select_t2` ( + `id` datetime(3) NOT NULL, + `a_boolean` array<boolean> NULL, + `a_tinyint` array<tinyint> NULL, + `a_smallint` array<smallint> NULL, + `a_int` array<int> NULL, + `a_bigint` array<bigint> NULL, + `a_largeint` array<largeint> NULL, + `a_float` array<float> NULL, + `a_double` array<double> NULL, + `a_decimal9` array<decimal(9,0)> NULL, + `a_decimal18` array<decimal(18,0)> NULL, + `a_decimal32` array<decimal(32,0)> NULL, + `a_date` array<date> NULL, + `a_datetime` array<datetime> NULL, + `a_char` array<char(1)> NULL, + `a_varchar` array<varchar(65533)> NULL, + `a_string` array<text> NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 01:00:00.000', [true], [-128], [-32768], [-2147483648], [-9223372036854775808], [-1234567890123456790], [-123.456], [-123456.789], [-123457], [-123456789012346], [-1234567890123456789012345678], ['0000-01-01'], ['0000-01-01 00:00:00'], ['A'], ['Hello'], ['Hello, Doris!']) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 02:00:00.000', [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL], [NULL]) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 03:00:00.000', [false], [127], [32767], [2147483647], [9223372036854775807], [1234567890123456789], [123.456], [123456.789], [123457], [123456789012346], [1234567890123456789012345678], ['9999-12-31'], ['9999-12-31 23:59:59'], [''], [''], ['']) + """ + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` values('2025-05-18 04:00:00.000', [true], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], ['2023-10-01'], ['2023-10-01 12:34:56'], ['A'], ['Hello'], ['Hello, Doris!']); + """ + + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_select_t3` ( + `id` datetime NOT NULL, + `datetime_0` datetime(0) NULL, + `datetime_1` datetime(1) NULL, + `datetime_3` datetime(2) NULL, + `datetime_4` datetime(3) NULL, + `datetime_5` datetime(4) NULL, + `datetime_6` datetime(5) NULL, + `datetime_7` datetime(6) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` values('2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111', '2025-05-18 01:00:00.111111'); + """ + + + + qt_sql """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` order by id + """ + + qt_sql """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t2` order by id + """ + + qt_sql """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` order by id + """ + + // test select after insert also get correct data, it seems we can newly partition version + sql """ + INSERT INTO `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` values('2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111', '2025-05-19 01:00:00.111111'); + """ + qt_query_after_insert """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t3` order by id + """ + + // test insert command + sql """ + CREATE TABLE `${db_name}`.`test_remote_doris_all_types_insert` ( + `id` datetime(3) NOT NULL, + `c_boolean` boolean NULL, + `c_tinyint` tinyint NULL, + `c_smallint` smallint NULL, + `c_int` int NULL, + `c_bigint` bigint NULL, + `c_largeint` largeint NULL, + `c_float` float NULL, + `c_double` double NULL, + `c_decimal9` decimal(9,0) NULL, + `c_decimal18` decimal(18,0) NULL, + `c_decimal32` decimal(32,0) NULL, + `c_date` date NULL, + `c_datetime` datetime NULL, + `c_char` char(1) NULL, + `c_varchar` varchar(65533) NULL, + `c_string` text NULL, + `c_array_s` array<text> NULL, + `c_map` MAP<STRING, INT> NULL, + `c_struct` STRUCT<f1:INT,f2:FLOAT,f3:STRING> NULL, + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + // test insert into + explain { + sql("insert into `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t`") + contains("VOlapScanNode") + } + sql """ + insert into `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` + """ + qt_after_insert_cmd """ + select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` order by id + """ + // test insert overwrite + explain { + sql("insert OVERWRITE table `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t`") + contains("VOlapScanNode") + } + sql """ + insert OVERWRITE table `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_insert` select /*+ SET_VAR(enable_nereids_distribute_planner=true, enable_sql_cache=true) */ * from `${catalog_name}`.`${db_name}`.`test_remote_doris_all_types_select_t` Review Comment: What is the behavior of setting these variables? Does it affect remote cluster? ########## fe/fe-core/src/main/java/org/apache/doris/datasource/doris/FeServiceClient.java: ########## @@ -173,42 +301,462 @@ public RemoteOlapTable getOlapTable(String dbName, String table, long tableId, L removedPartitions = new ArrayList<>(); } remoteOlapTable.rebuildPartitions(partitions, updatedPartitions, removedPartitions); + // rebuild temp partitions + if (result.isSetUpdatedTempPartitions() && result.getUpdatedTempPartitionsSize() > 0) { + updatedPartitions = new ArrayList<>(result.getUpdatedTempPartitionsSize()); + for (ByteBuffer buffer : result.getUpdatedTempPartitions()) { + try (ByteArrayInputStream in = + new ByteArrayInputStream(buffer.array(), buffer.position(), buffer.remaining()); + DataInputStream dataInputStream = new DataInputStream(in)) { + String partitionStr = Text.readString(dataInputStream); + Partition partition = GsonUtils.GSON.fromJson(partitionStr, Partition.class); + updatedPartitions.add(partition); + } + } + } + removedPartitions = result.getRemovedTempPartitions(); + if (removedPartitions == null) { + removedPartitions = new ArrayList<>(); + } + remoteOlapTable.rebuildTempPartitions(tempPartitions, updatedPartitions, removedPartitions); return remoteOlapTable; - }, msg, timeout); + }, msg, timeoutMs); + } + + public TBeginRemoteTxnResult beginRemoteTxn(TBeginRemoteTxnRequest request) throws Exception { + request.setUser(user); + request.setPasswd(password); + String msg = String.format("failed to begin remote txn from remote doris:%s, label=%s", name, + request.getLabel()); + long startTime = System.currentTimeMillis(); + TBeginRemoteTxnResult result; + try { + result = masterCallWithRetry(client -> client.beginRemoteTxn(request), msg, + Math.max(timeoutMs, (int) request.getTimeoutMs())); + } catch (Exception e) { + long costMs = System.currentTimeMillis() - startTime; + LOG.warn("begin remote txn for catalog {} failed, cost={}ms", name, costMs, e); + throw e; + } + + long costMs = System.currentTimeMillis() - startTime; + LOG.info("begin remote txn for catalog {} finished, cost={}ms, statusCode={}", + name, costMs, result.getStatus().getStatusCode()); + return result; + } + + public TCommitRemoteTxnResult commitRemoteTxn(TCommitRemoteTxnRequest request) throws Exception { + request.setUser(user); + request.setPasswd(password); + String msg = String.format("failed to commit remote txn from remote doris:%s, txnId=%d", name, + request.getTxnId()); + long startTime = System.currentTimeMillis(); + TCommitRemoteTxnResult result; + try { + result = masterCallWithRetry(client -> client.commitRemoteTxn(request), msg, + Math.max(timeoutMs, (int) request.getInsertVisibleTimeoutMs())); + } catch (Exception e) { + long costMs = System.currentTimeMillis() - startTime; + LOG.warn("commit remote txn for catalog {} failed, txnId={}, cost={}ms", + name, request.getTxnId(), costMs, e); + throw e; + } + + long costMs = System.currentTimeMillis() - startTime; + LOG.info("commit remote txn for catalog {} finished, txnId={}, cost={}ms, statusCode={}", + name, request.getTxnId(), costMs, result.getStatus().getStatusCode()); + return result; + } + + public TAbortRemoteTxnResult abortRemoteTxn(TAbortRemoteTxnRequest request) throws Exception { + request.setUser(user); + request.setPasswd(password); + String msg = String.format("failed to abort remote txn from remote doris:%s, txnId=%d", name, + request.getTxnId()); + long startTime = System.currentTimeMillis(); + TAbortRemoteTxnResult result; + try { + result = masterCallWithRetry(client -> client.abortRemoteTxn(request), msg, timeoutMs); + } catch (Exception e) { + long costMs = System.currentTimeMillis() - startTime; + LOG.warn("abort remote txn for catalog {} failed, txnId={}, cost={}ms", + name, request.getTxnId(), costMs, e); + throw e; + } + + long costMs = System.currentTimeMillis() - startTime; + LOG.info("abort remote txn for catalog {} finished, txnId={}, cost={}ms, statusCode={}", + name, request.getTxnId(), costMs, result.getStatus().getStatusCode()); + return result; } private interface ThriftCall<T> { public T call(FrontendService.Client client) throws Exception; } - private static class MasterResult<T> { - boolean isMaster = true; - T result; - boolean hasError = false; - String errorMsg; + public TNetworkAddress getMasterAddress() throws RuntimeException { + TMasterAddressRequest request = new TMasterAddressRequest(); + request.setUser(user); + request.setPasswd(password); + long startTime = System.currentTimeMillis(); + TMasterAddressResult result; + try { + result = masterCallWithRetry(client -> client.getMasterAddress(request), + "failed to get master address from remote doris:" + name, timeoutMs); + if (result.isSetMasterAddress()) { + master = result.getMasterAddress(); + } + if (result.getStatus().getStatusCode() != TStatusCode.OK) { + throw new RuntimeException(result.getStatus().getErrorMsgs().get(0)); + } + } catch (Exception e) { + long costMs = System.currentTimeMillis() - startTime; + LOG.warn("get master address for catalog {} failed, cost={}ms", name, costMs, e); + throw new RuntimeException(e.getMessage()); Review Comment: ```suggestion throw new RuntimeException(Util.getRootCause(e), e); ``` Same suggestion for other places ########## gensrc/thrift/FrontendService.thrift: ########## @@ -1662,13 +1662,178 @@ struct TGetOlapTableMetaRequest { 5: required i64 table_id 6: optional i32 version // todo serialize according to the version 7: optional list<TPartitionMeta> partitions // client owned partition meta + 8: optional list<TPartitionMeta> temp_partitions // client owned partition meta } struct TGetOlapTableMetaResult { 1: required Status.TStatus status 2: required binary table_meta 3: optional list<binary> updated_partitions 4: optional list<i64> removed_partitions + 5: optional list<binary> updated_temp_partitions + 6: optional list<i64> removed_temp_partitions +} + +// Remote transaction request and Result definitions for cross-cluster export. +// These structs are used by beginRemoteTxn/commitRemoteTxn/abortRemoteTxn RPCs. +struct TBeginRemoteTxnRequest { + 1: required string user + 2: required string passwd + 3: optional string token + 4: required string db Review Comment: better add `catalog`, even if currently only support "internal" catalog -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
