Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hdfs-table-writer.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "exec/hdfs-table-writer.h"
16 
17 #include "common/names.h"
18 
19 namespace impala {
20 
22  RuntimeState* state, OutputPartition* output,
23  const HdfsPartitionDescriptor* partition_desc,
24  const HdfsTableDescriptor* table_desc,
25  const vector<ExprContext*>& output_expr_ctxs)
26  : parent_(parent),
27  state_(state),
28  output_(output),
29  table_desc_(table_desc),
30  output_expr_ctxs_(output_expr_ctxs) {
31  int num_non_partition_cols =
33  DCHECK_GE(output_expr_ctxs_.size(), num_non_partition_cols) << parent_->DebugString();
34 }
35 
36 Status HdfsTableWriter::Write(const uint8_t* data, int32_t len) {
37  DCHECK_GE(len, 0);
38  int ret = hdfsWrite(output_->hdfs_connection, output_->tmp_hdfs_file, data, len);
39  if (ret == -1) {
40  string error_msg = GetHdfsErrorMsg("");
41  stringstream msg;
42  msg << "Failed to write data (length: " << len
43  << ") to Hdfs file: " << output_->current_file_name
44  << " " << error_msg;
45  return Status(msg.str());
46  }
48  stats_.bytes_written += len;
49  return Status::OK;
50 }
51 }
HdfsTableSink * parent_
Parent table sink object.
Status Write(const char *data, int32_t len)
Write to the current hdfs file.
const HdfsTableDescriptor * table_desc_
Table descriptor of table to be written.
#define COUNTER_ADD(c, v)
std::string DebugString() const
HdfsTableWriter(HdfsTableSink *parent, RuntimeState *state, OutputPartition *output_partition, const HdfsPartitionDescriptor *partition_desc, const HdfsTableDescriptor *table_desc, const std::vector< ExprContext * > &output_expr_ctxs)
hdfsFS hdfs_connection
Connection to hdfs.
int num_clustering_cols() const
Definition: descriptors.h:153
RuntimeProfile::Counter * bytes_written_counter()
hdfsFile tmp_hdfs_file
Hdfs file at tmp_hdfs_file_name.
std::vector< ExprContext * > output_expr_ctxs_
Expressions that materialize output values.
TInsertStats stats_
Subclass should populate any file format specific stats.
static const Status OK
Definition: status.h:87
Metadata for a single partition inside an Hdfs table.
Definition: descriptors.h:177
string GetHdfsErrorMsg(const string &prefix, const string &file)
Definition: hdfs-util.cc:26
OutputPartition * output_
Structure describing partition written to by this writer.