diff --git a/regression-test/data/export_p0/outfile/outfile_expr/test_outfile_expression_generate_col_name.out b/regression-test/data/export_p0/outfile/outfile_expr/test_outfile_expression_generate_col_name.out new file mode 100644 index 000000000000000..c96b321f74fca64 --- /dev/null +++ b/regression-test/data/export_p0/outfile/outfile_expr/test_outfile_expression_generate_col_name.out @@ -0,0 +1,267 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_base -- +1 doris-1 19 +10 \N \N +2 doris-2 20 +3 doris-3 21 +4 doris-4 22 +5 doris-5 23 +6 doris-6 24 +7 doris-7 25 +8 doris-8 26 +9 doris-9 27 + +-- !select_base1 -- +false +false +false +false +false +false +false +false +false +false + +-- !select_tvf -- +false +false +false +false +false +false +false +false +false +false + +-- !desc_s3 -- +__greater_than_0 BOOLEAN Yes false \N NONE + +-- !select_base1 -- +10 + +-- !select_tvf -- +false + +-- !desc_s3 -- +__max_0 BOOLEAN Yes false \N NONE + +-- !select_base1 -- +1 id = 1 +10 id not exist +2 id = 2 +3 id not exist +4 id not exist +5 id not exist +6 id not exist +7 id not exist +8 id not exist +9 id not exist + +-- !select_tvf -- +false false +false true +false true +false true +false true +false true +false true +true true +true true +true true + +-- !desc_s3 -- +__case_when_1 BOOLEAN Yes false \N NONE +id BOOLEAN Yes false \N NONE + +-- !select_base1 -- +1 1 string 19 false 5 true 1 +10 1 string \N false 5 true 1 +2 1 string 20 false 5 true 1 +3 1 string 21 false 5 true 1 +4 1 string 22 false 5 true 1 +5 1 string 23 false 5 true 1 +6 1 string 24 false 5 true 1 +7 1 string 25 false 5 true 1 +8 1 string 26 false 5 true 1 +9 1 string 27 false 5 true 1 + +-- !select_tvf -- +false true false false false true true true +false true true false false true true true +false true true false false true true true +false true true true false true true true +false true true true false true true true +false true true true false true true true +false true true true false true true true +true true true false false true true true +true true true true false true true true +true true true true false true true true + +-- !desc_s3 -- +__add_5 BOOLEAN Yes false \N NONE +__bit_or_7 BOOLEAN Yes false \N NONE +__cast_3 BOOLEAN Yes false \N NONE +__greater_than_4 BOOLEAN Yes false \N NONE +__in_predicate_6 BOOLEAN Yes false \N NONE +__literal_1 BOOLEAN Yes false \N NONE +__literal_2 BOOLEAN Yes false \N NONE +id BOOLEAN Yes false \N NONE + +-- !select_base1 -- +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 + +-- !select_tvf -- +false false false +false true false +true true true +true true true +true true true +true true true +true true true +true true true +true true true +true true true + +-- !desc_s3 -- +__cast_0 BOOLEAN Yes false \N NONE +__cast_1 BOOLEAN Yes false \N NONE +__cast_2 BOOLEAN Yes false \N NONE + +-- !select_base1 -- +false +false +false +false +false +false +false +false +false +false + +-- !select_tvf -- +false +false +false +false +false +false +false +false +false +false + +-- !desc_s3 -- +__greater_than_0 BOOLEAN Yes false \N NONE + +-- !select_base1 -- +10 + +-- !select_tvf -- +10 + +-- !desc_s3 -- +__max_0 INT Yes false \N NONE + +-- !select_base1 -- +1 id = 1 +10 id not exist +2 id = 2 +3 id not exist +4 id not exist +5 id not exist +6 id not exist +7 id not exist +8 id not exist +9 id not exist + +-- !select_tvf -- +1 id = 1 +10 id not exist +2 id = 2 +3 id not exist +4 id not exist +5 id not exist +6 id not exist +7 id not exist +8 id not exist +9 id not exist + +-- !desc_s3 -- +__case_when_1 TEXT Yes false \N NONE +id INT Yes false \N NONE + +-- !select_base1 -- +1 1 string 19 false 5 true 1 +10 1 string \N false 5 true 1 +2 1 string 20 false 5 true 1 +3 1 string 21 false 5 true 1 +4 1 string 22 false 5 true 1 +5 1 string 23 false 5 true 1 +6 1 string 24 false 5 true 1 +7 1 string 25 false 5 true 1 +8 1 string 26 false 5 true 1 +9 1 string 27 false 5 true 1 + +-- !select_tvf -- +1 1 string 19 false 5 true 1 +10 1 string \N false 5 true 1 +2 1 string 20 false 5 true 1 +3 1 string 21 false 5 true 1 +4 1 string 22 false 5 true 1 +5 1 string 23 false 5 true 1 +6 1 string 24 false 5 true 1 +7 1 string 25 false 5 true 1 +8 1 string 26 false 5 true 1 +9 1 string 27 false 5 true 1 + +-- !desc_s3 -- +__add_5 SMALLINT Yes false \N NONE +__bit_or_7 TINYINT Yes false \N NONE +__cast_3 BIGINT Yes false \N NONE +__greater_than_4 BOOLEAN Yes false \N NONE +__in_predicate_6 BOOLEAN Yes false \N NONE +__literal_1 TINYINT Yes false \N NONE +__literal_2 TEXT Yes false \N NONE +id INT Yes false \N NONE + +-- !select_base1 -- +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 + +-- !select_tvf -- +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 +2566 888 9999 + +-- !desc_s3 -- +__cast_0 TEXT Yes false \N NONE +__cast_1 BIGINT Yes false \N NONE +__cast_2 TEXT Yes false \N NONE + diff --git a/regression-test/suites/export_p0/outfile/outfile_expr/test_outfile_expression_generate_col_name.groovy b/regression-test/suites/export_p0/outfile/outfile_expr/test_outfile_expression_generate_col_name.groovy new file mode 100644 index 000000000000000..6c9806027196465 --- /dev/null +++ b/regression-test/suites/export_p0/outfile/outfile_expr/test_outfile_expression_generate_col_name.groovy @@ -0,0 +1,259 @@ +// 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. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +import java.nio.charset.StandardCharsets +import java.nio.file.Files +import java.nio.file.Paths + +suite("test_outfile_expression_generate_col_name", "p0") { + // close nereids + sql """ set enable_nereids_planner = true """ + sql """ set enable_fallback_to_original_planner = false """ + + String ak = getS3AK() + String sk = getS3SK() + String s3_endpoint = getS3Endpoint() + String region = getS3Region() + String bucket = getS3BucketName(); + + def export_table_name = "outfile_expr_export_test" + def outFilePath = "${bucket}/outfile/expression_generate_col_name/exp_" + + def create_table = { + sql """ DROP TABLE IF EXISTS ${export_table_name} """ + sql """ + CREATE TABLE IF NOT EXISTS ${export_table_name} ( + `id` int(11) NULL, + `name` string NULL, + `age` int(11) NULL + ) + PARTITION BY RANGE(id) + ( + PARTITION less_than_20 VALUES LESS THAN ("20"), + PARTITION between_20_70 VALUES [("20"),("70")), + PARTITION more_than_70 VALUES LESS THAN ("151") + ) + DISTRIBUTED BY HASH(id) BUCKETS 3 + PROPERTIES("replication_num" = "1"); + """ + } + + def outfile_to_S3 = { format -> + // select ... into outfile ... + def res = sql """ + SELECT * FROM ${export_table_name} t ORDER BY user_id + INTO OUTFILE "s3://${outFilePath}" + FORMAT AS ${outfile_format} + PROPERTIES ( + "s3.endpoint" = "${s3_endpoint}", + "s3.region" = "${region}", + "s3.secret_key"="${sk}", + "s3.access_key" = "${ak}" + ); + """ + + return res[0][3] + } + + // create table to export data + create_table() + + // insert data + StringBuilder sb = new StringBuilder() + int i = 1 + for (; i < 10; i ++) { + sb.append(""" + (${i}, 'doris-${i}', ${i + 18}), + """) + } + sb.append(""" + (${i}, NULL, NULL) + """) + sql """ INSERT INTO ${export_table_name} VALUES + ${sb.toString()} + """ + def insert_res = sql "show last insert;" + logger.info("insert result: " + insert_res.toString()) + order_qt_select_base """ SELECT * FROM ${export_table_name} t ORDER BY id; """ + + + + def check_outfile_data = { outfile_url, outfile_format -> + order_qt_select_tvf """ SELECT * FROM S3 ( + "uri" = "http://${s3_endpoint}${outfile_url.substring(4)}0.${outfile_format}", + "ACCESS_KEY"= "${ak}", + "SECRET_KEY" = "${sk}", + "format" = "${outfile_format}", + "region" = "${region}" + ); + """ + } + + def check_outfile_column_name = { outfile_url, outfile_format -> + order_qt_desc_s3 """ Desc function S3 ( + "uri" = "http://${s3_endpoint}${outfile_url.substring(4)}0.${outfile_format}", + "ACCESS_KEY"= "${ak}", + "SECRET_KEY" = "${sk}", + "format" = "${outfile_format}", + "region" = "${region}" + ); + """ + } + + def test_q1 = { outfile_format -> + order_qt_select_base1 """ select 1>2 from ${export_table_name} """ + + // select ... into outfile ... + def res = sql """ + SELECT 1>2 FROM ${export_table_name} + INTO OUTFILE "s3://${outFilePath}" + FORMAT AS ${outfile_format} + PROPERTIES ( + "s3.endpoint" = "${s3_endpoint}", + "s3.region" = "${region}", + "s3.secret_key"="${sk}", + "s3.access_key" = "${ak}" + ); + """ + outfile_url = res[0][3] + + check_outfile_data(outfile_url, outfile_format) + check_outfile_column_name(outfile_url, outfile_format) + } + + def test_q2 = { outfile_format -> + order_qt_select_base1 """ select max(id) from ${export_table_name} """ + + // select ... into outfile ... + def res = sql """ + SELECT max(id) FROM ${export_table_name} + INTO OUTFILE "s3://${outFilePath}" + FORMAT AS ${outfile_format} + PROPERTIES ( + "s3.endpoint" = "${s3_endpoint}", + "s3.region" = "${region}", + "s3.secret_key"="${sk}", + "s3.access_key" = "${ak}" + ); + """ + outfile_url = res[0][3] + + check_outfile_data(outfile_url, outfile_format) + check_outfile_column_name(outfile_url, outfile_format) + } + + def test_q3 = { outfile_format -> + order_qt_select_base1 """ select id, case id when 1 then 'id = 1' when 2 then 'id = 2' else 'id not exist' end from ${export_table_name} """ + + // select ... into outfile ... + def res = sql """ + SELECT id, case id when 1 then 'id = 1' when 2 then 'id = 2' else 'id not exist' end FROM ${export_table_name} + INTO OUTFILE "s3://${outFilePath}" + FORMAT AS ${outfile_format} + PROPERTIES ( + "s3.endpoint" = "${s3_endpoint}", + "s3.region" = "${region}", + "s3.secret_key"="${sk}", + "s3.access_key" = "${ak}" + ); + """ + outfile_url = res[0][3] + + check_outfile_data(outfile_url, outfile_format) + check_outfile_column_name(outfile_url, outfile_format) + } + + def test_q4 = { outfile_format -> + order_qt_select_base1 """ select + id, + 1, + 'string', + cast (age AS BIGINT), + 1 > 2, + 2 + 3, + 1 IN (1, 2, 3, 4), + TRUE | FALSE + from ${export_table_name} + """ + + // select ... into outfile ... + def res = sql """ + select + id, + 1, + 'string', + cast (age AS BIGINT), + 1 > 2, + 2 + 3, + 1 IN (1, 2, 3, 4), + TRUE | FALSE + from ${export_table_name} + INTO OUTFILE "s3://${outFilePath}" + FORMAT AS ${outfile_format} + PROPERTIES ( + "s3.endpoint" = "${s3_endpoint}", + "s3.region" = "${region}", + "s3.secret_key"="${sk}", + "s3.access_key" = "${ak}" + ); + """ + outfile_url = res[0][3] + + check_outfile_data(outfile_url, outfile_format) + check_outfile_column_name(outfile_url, outfile_format) + } + + def test_q5 = { outfile_format -> + order_qt_select_base1 """ select cast('2566' as string), cast('888' as bigint), cast('9999' as largeint) + from ${export_table_name} + """ + + // select ... into outfile ... + def res = sql """ + select cast('2566' as string), cast('888' as bigint), cast('9999' as largeint) + from ${export_table_name} + INTO OUTFILE "s3://${outFilePath}" + FORMAT AS ${outfile_format} + PROPERTIES ( + "s3.endpoint" = "${s3_endpoint}", + "s3.region" = "${region}", + "s3.secret_key"="${sk}", + "s3.access_key" = "${ak}" + ); + """ + outfile_url = res[0][3] + + check_outfile_data(outfile_url, outfile_format) + check_outfile_column_name(outfile_url, outfile_format) + } + + // test parquet format + test_q1("parquet") + test_q2("parquet") + test_q3("parquet") + test_q4("parquet") + test_q5("parquet") + + // test orc format + test_q1("orc") + test_q2("orc") + test_q3("orc") + test_q4("orc") + test_q5("orc") +}