Files
doris/be/src/exec/hdfs_writer.h
EmmyMiao87 bdc8c98008 [Outfile] Support hdfs in select outfile clause (#6644)
Support hdfs in select outfile clause without broker.
This PR implement a HDFS writer in BE which is used to write HDFS file directly without using broker.
Also the hdfs outfile clause syntax check has been added in FE.
The syntax:
```
select * from xx into outfile "hdfs://user/outfile_" format as csv
properties ("hdfs.fs.dafultFS" = "xxx", "hdfs.hdfs_user" = "xxx");
```
Note that all hdfs configurations need to carry a prefix `hdfs.`.
2021-09-24 10:07:11 +08:00

57 lines
1.8 KiB
C++

// 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.
#pragma once
#include <hdfs/hdfs.h>
#include <map>
#include <string>
#include "exec/file_writer.h"
namespace doris {
class HDFSWriter : public FileWriter {
public:
HDFSWriter(std::map<std::string, std::string>& properties, const std::string& path);
~HDFSWriter();
Status open() override;
// Writes up to count bytes from the buffer pointed buf to the file.
// NOTE: the number of bytes written may be less than count if.
Status write(const uint8_t* buf, size_t buf_len, size_t* written_len) override;
Status close() override;
private:
Status _connect();
Status _parse_properties(std::map<std::string, std::string>& prop);
std::map<std::string, std::string> _properties;
std::string _user = "";
std::string _namenode = "";
std::string _path = "";
std::string _kerb_principal = "";
std::string _kerb_ticket_cache_path = "";
std::string _token = "";
hdfsFS _hdfs_fs = nullptr;
hdfsFile _hdfs_file = nullptr;
bool _closed = false;
};
}