github-actions[bot] commented on code in PR #61820: URL: https://github.com/apache/doris/pull/61820#discussion_r3050729257
########## be/src/core/data_type/file_schema_descriptor.cpp: ########## @@ -0,0 +1,161 @@ +// 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. + +#include "core/data_type/file_schema_descriptor.h" + +#include <algorithm> +#include <cctype> +#include <cstring> +#include <unordered_map> + +#include "common/cast_set.h" +#include "core/data_type/data_type_nullable.h" +#include "core/data_type/data_type_number.h" +#include "core/data_type/data_type_string.h" + +namespace doris { + +const FileSchemaDescriptor& FileSchemaDescriptor::instance() { + static const FileSchemaDescriptor descriptor; + return descriptor; +} + +FileSchemaDescriptor::FileSchemaDescriptor() { + auto add_field = [this](const char* name, DataTypePtr type) { + _fields.emplace_back(FileFieldDesc { + .name = name, + .type = std::move(type), + }); + }; + + add_field("uri", std::make_shared<DataTypeString>(4096, TYPE_VARCHAR)); + add_field("file_name", std::make_shared<DataTypeString>(512, TYPE_VARCHAR)); + add_field("content_type", std::make_shared<DataTypeString>(128, TYPE_VARCHAR)); + add_field("size", std::make_shared<DataTypeInt64>()); + add_field("region", make_nullable(std::make_shared<DataTypeString>(64, TYPE_VARCHAR))); + add_field("endpoint", make_nullable(std::make_shared<DataTypeString>(256, TYPE_VARCHAR))); + add_field("ak", make_nullable(std::make_shared<DataTypeString>(256, TYPE_VARCHAR))); + add_field("sk", make_nullable(std::make_shared<DataTypeString>(256, TYPE_VARCHAR))); + add_field("role_arn", make_nullable(std::make_shared<DataTypeString>(256, TYPE_VARCHAR))); + add_field("external_id", make_nullable(std::make_shared<DataTypeString>(256, TYPE_VARCHAR))); +} + +std::string FileSchemaDescriptor::extract_file_name(std::string_view uri) { + // Strip query string / fragment + size_t end = uri.find_first_of("?#"); + std::string_view path = (end == std::string_view::npos) ? uri : uri.substr(0, end); + size_t pos = path.find_last_of('/'); + if (pos == std::string_view::npos) { + return std::string(path); + } + if (pos + 1 >= path.size()) { + return ""; + } + return std::string(path.substr(pos + 1)); +} + +std::string FileSchemaDescriptor::extract_file_extension(const std::string& file_name) { + size_t pos = file_name.find_last_of('.'); + if (pos == std::string::npos) { + return ""; + } + std::string extension = file_name.substr(pos); + std::transform(extension.begin(), extension.end(), extension.begin(), + [](unsigned char ch) { return static_cast<char>(std::tolower(ch)); }); + return extension; +} + +std::string FileSchemaDescriptor::extension_to_content_type(const std::string& ext) { + static const std::unordered_map<std::string, std::string> mime_map = { + {".csv", "text/csv"}, + {".tsv", "text/tab-separated-values"}, + {".json", "application/json"}, + {".jsonl", "application/x-ndjson"}, + {".parquet", "application/x-parquet"}, + {".orc", "application/x-orc"}, + {".avro", "application/avro"}, + {".txt", "text/plain"}, + {".log", "text/plain"}, + {".tbl", "text/plain"}, + {".xml", "application/xml"}, + {".html", "text/html"}, + {".htm", "text/html"}, + {".pdf", "application/pdf"}, + {".jpg", "image/jpeg"}, + {".jpeg", "image/jpeg"}, + {".png", "image/png"}, + {".gif", "image/gif"}, + {".bmp", "image/bmp"}, + {".svg", "image/svg+xml"}, + {".webp", "image/webp"}, + {".mp3", "audio/mpeg"}, + {".wav", "audio/wav"}, + {".mp4", "video/mp4"}, + {".avi", "video/x-msvideo"}, + {".gz", "application/gzip"}, + {".bz2", "application/x-bzip2"}, + {".zst", "application/zstd"}, + {".lz4", "application/x-lz4"}, + {".snappy", "application/x-snappy"}, + {".zip", "application/zip"}, + {".tar", "application/x-tar"}, + }; + if (auto it = mime_map.find(ext); it != mime_map.end()) { + return it->second; + } + return "application/octet-stream"; +} + +void FileSchemaDescriptor::write_jsonb_string(JsonbWriter& writer, const std::string& value) { + writer.writeStartString(); + writer.writeString(value.data(), cast_set<uint32_t>(value.size())); + writer.writeEndString(); +} + +void FileSchemaDescriptor::write_jsonb_key(JsonbWriter& writer, std::string_view key) { + writer.writeKey(key.data(), cast_set<uint8_t>(key.size())); +} + +void FileSchemaDescriptor::write_file_jsonb(JsonbWriter& writer, const FileMetadata& metadata) { + const auto& schema = instance(); + auto write_nullable_str = [&](Field field, const std::string& s) { + write_jsonb_key(writer, schema.field_name(field)); + if (s.empty()) { + writer.writeNull(); + } else { + write_jsonb_string(writer, s); + } + }; + + writer.writeStartObject(); + write_jsonb_key(writer, schema.field_name(Field::URI)); + write_jsonb_string(writer, metadata.uri); + write_jsonb_key(writer, schema.field_name(Field::FILE_NAME)); + write_jsonb_string(writer, metadata.file_name); + write_jsonb_key(writer, schema.field_name(Field::CONTENT_TYPE)); + write_jsonb_string(writer, metadata.content_type); + write_jsonb_key(writer, schema.field_name(Field::SIZE)); + writer.writeInt64(metadata.size); + write_nullable_str(Field::REGION, metadata.region); + write_nullable_str(Field::ENDPOINT, metadata.endpoint); + write_nullable_str(Field::AK, metadata.ak); Review Comment: `write_file_jsonb()` serializes `ak` / `sk` (and the FILESET reader populates those fields from `AWS_ACCESS_KEY` / `AWS_SECRET_KEY`) directly into the user-visible `FILE` value. That means any user with normal `SELECT` access can recover the backing object-store credentials via `file.ak` / `file.sk`, and those secrets will also flow through result sets, spills, and logs. The auth material needs to stay in backend-only scan state, not inside the exposed `FILE` payload. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToFile.java: ########## @@ -0,0 +1,75 @@ +// 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. + +package org.apache.doris.nereids.trees.expressions.functions.scalar; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.FileType; +import org.apache.doris.nereids.types.StringType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'to_file'. + * to_file(url, region, endpoint, ak, sk) — construct FILE with auth info. + */ +public class ToFile extends ScalarFunction + implements ExplicitlyCastableSignature, PropagateNullable { + + public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( Review Comment: This class only registers a 5-argument signature, and the BE implementation also requires 5 arguments. As a result, the PR's documented `to_file("<url>")` form still fails function binding with no matching overload. If the intended public API is the one shown in the PR description, this patch needs to add the corresponding overload end-to-end. -- 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]
