15 package com.cloudera.impala.analysis;
17 import java.io.FileNotFoundException;
18 import java.io.IOException;
20 import org.apache.hadoop.fs.FileStatus;
21 import org.apache.hadoop.fs.FileSystem;
22 import org.apache.hadoop.fs.permission.FsAction;
23 import org.apache.hadoop.fs.Path;
24 import org.apache.hadoop.hdfs.DistributedFileSystem;
33 import com.cloudera.impala.thrift.TLoadDataReq;
34 import com.cloudera.impala.thrift.TTableName;
37 import com.google.common.base.Preconditions;
64 Preconditions.checkNotNull(tableName);
65 Preconditions.checkNotNull(sourceDataPath);
66 this.tableName_ = tableName;
67 this.sourceDataPath_ = sourceDataPath;
68 this.overwrite_ = overwrite;
69 this.partitionSpec_ = partitionSpec;
73 return tableName_.getTbl();
77 Preconditions.checkNotNull(
dbName_);
87 StringBuilder sb =
new StringBuilder(
"LOAD DATA INPATH '");
90 sb.append(
"INTO TABLE " + tableName_.toString());
91 if (
partitionSpec_ != null) sb.append(
" " + partitionSpec_.toSql());
107 partitionSpec_.setPartitionShouldExist();
109 partitionSpec_.analyze(analyzer);
111 if (table.getMetaStoreTable().getPartitionKeysSize() > 0) {
133 Path source = sourceDataPath_.getPath();
134 FileSystem fs = source.getFileSystem(FileSystemUtil.getConfiguration());
135 if (!(fs instanceof DistributedFileSystem)) {
139 if (!fs.exists(source)) {
149 if (fs.isDirectory(source)) {
156 "INPATH location '%s' cannot contain subdirectories.",
sourceDataPath_));
159 FsAction.READ_WRITE)) {
161 "because Impala does not have READ and WRITE permissions on this directory",
168 "INPATH location '%s' points to a hidden file.", source));
171 if (!checker.
getPermissions(fs, source.getParent()).checkPermissions(
174 "because Impala does not have WRITE permissions on its parent " +
175 "directory %s", source, source.getParent()));
181 "because Impala does not have READ permissions on this file", source));
185 String noWriteAccessErrorMsg = String.format(
"Unable to LOAD DATA into " +
186 "target table (%s) because Impala does not have WRITE access to HDFS " +
187 "location: ", hdfsTable.getFullName());
192 partition = hdfsTable.getPartition(partitionSpec_.getPartitionSpecKeyValues());
193 location = partition.getLocation();
199 partition = hdfsTable.getPartitions().
get(0);
200 location = hdfsTable.getLocation();
201 if (!hdfsTable.hasWriteAccess()) {
205 Preconditions.checkNotNull(partition);
211 "Unable to LOAD DATA into target table (%s) because source path (%s) and " +
212 "destination %s (%s) are on different filesystems.",
213 hdfsTable.getFullName(),
215 partition.getLocation()));
218 for (FileStatus fStatus: fs.listStatus(source)) {
219 if (fs.isDirectory(fStatus.getPath()))
continue;
220 StringBuilder errorMsg =
new StringBuilder();
221 HdfsFileFormat fileFormat = partition.getInputFormatDescriptor().getFileFormat();
227 }
catch (FileNotFoundException e) {
229 }
catch (IOException e) {
235 TLoadDataReq loadDataReq =
new TLoadDataReq();
236 loadDataReq.setTable_name(
new TTableName(
getDb(),
getTbl()));
237 loadDataReq.setSource_path(sourceDataPath_.toString());
240 loadDataReq.setPartition_spec(partitionSpec_.toThrift());
void analyze(Analyzer analyzer)
static boolean containsSubdirectory(Path directory)
void analyzePaths(Analyzer analyzer, HdfsTable hdfsTable)
Permissions getPermissions(FileSystem fs, Path path)
final HdfsUri sourceDataPath_
LoadDataStmt(TableName tableName, HdfsUri sourceDataPath, boolean overwrite, PartitionSpec partitionSpec)
final TableName tableName_
final PartitionSpec partitionSpec_
static boolean isHiddenFile(String fileName)
static boolean impliesWriteAccess(TAccessLevel level)
static int getTotalNumVisibleFiles(Path directory)
TAccessLevel getAccessLevel()
static Boolean isPathOnFileSystem(Path path, FileSystem fs)