| 199 | } |
| 200 | |
| 201 | Status TableSinkBase::InitOutputPartition(RuntimeState* state, |
| 202 | const HdfsPartitionDescriptor& partition_descriptor, |
| 203 | OutputPartition* output_partition, bool empty_partition) { |
| 204 | BuildHdfsFileNames(partition_descriptor, output_partition); |
| 205 | |
| 206 | if (ShouldSkipStaging(state, output_partition)) { |
| 207 | // We will be writing to the final file if we're skipping staging, so get a connection |
| 208 | // to its filesystem. |
| 209 | RETURN_IF_ERROR(HdfsFsCache::instance()->GetConnection( |
| 210 | output_partition->final_hdfs_file_name_prefix, |
| 211 | &output_partition->hdfs_connection)); |
| 212 | } else { |
| 213 | // Else get a connection to the filesystem of the tmp file. |
| 214 | RETURN_IF_ERROR(HdfsFsCache::instance()->GetConnection( |
| 215 | output_partition->tmp_hdfs_file_name_prefix, &output_partition->hdfs_connection)); |
| 216 | } |
| 217 | |
| 218 | output_partition->partition_descriptor = &partition_descriptor; |
| 219 | |
| 220 | if (partition_descriptor.file_format() == THdfsFileFormat::SEQUENCE_FILE || |
| 221 | partition_descriptor.file_format() == THdfsFileFormat::AVRO) { |
| 222 | stringstream error_msg; |
| 223 | map<int, const char*>::const_iterator i = |
| 224 | _THdfsFileFormat_VALUES_TO_NAMES.find(partition_descriptor.file_format()); |
| 225 | error_msg << "Writing to table format " << i->second << " is not supported."; |
| 226 | return Status(error_msg.str()); |
| 227 | } |
| 228 | if (partition_descriptor.file_format() == THdfsFileFormat::TEXT && |
| 229 | state->query_options().__isset.compression_codec && |
| 230 | state->query_options().compression_codec.codec != THdfsCompression::NONE) { |
| 231 | stringstream error_msg; |
| 232 | error_msg << "Writing to compressed text table is not supported. "; |
| 233 | return Status(error_msg.str()); |
| 234 | } |
| 235 | |
| 236 | // It is incorrect to initialize a writer if there are no rows to feed it. The writer |
| 237 | // could incorrectly create an empty file or empty partition. |
| 238 | // However, for transactional tables we should create a new empty base directory in |
| 239 | // case of INSERT OVERWRITEs. |
| 240 | if (empty_partition && (!is_overwrite() || !IsTransactional())) return Status::OK(); |
| 241 | |
| 242 | switch (partition_descriptor.file_format()) { |
| 243 | case THdfsFileFormat::TEXT: |
| 244 | output_partition->writer.reset( |
| 245 | new HdfsTextTableWriter( |
| 246 | this, state, output_partition, &partition_descriptor, table_desc_)); |
| 247 | break; |
| 248 | case THdfsFileFormat::ICEBERG: |
| 249 | case THdfsFileFormat::PARQUET: |
| 250 | output_partition->writer.reset( |
| 251 | new HdfsParquetTableWriter( |
| 252 | this, state, output_partition, &partition_descriptor, table_desc_)); |
| 253 | break; |
| 254 | case THdfsFileFormat::PUFFIN: |
| 255 | output_partition->writer.reset( |
| 256 | new PuffinWriter( |
| 257 | this, state, output_partition, &partition_descriptor, table_desc_)); |
| 258 | break; |
nothing calls this directly
no test coverage detected