Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 2 additions & 46 deletions hplsql/src/main/antlr4/org/apache/hive/hplsql/Hplsql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ stmt :
| collect_stats_stmt
| close_stmt
| cmp_stmt
| copy_from_local_stmt
| copy_stmt
| commit_stmt
| create_database_stmt
Expand Down Expand Up @@ -99,8 +98,6 @@ stmt :
| while_stmt
| unconditional_loop_stmt
| label
| hive
| host
| null_stmt
| expr_stmt
| semicolon_stmt // Placed here to allow null statements ;;...
Expand Down Expand Up @@ -642,18 +639,10 @@ cmp_stmt : // CMP statement
cmp_source :
(table_name where_clause? | T_OPEN_P select_stmt T_CLOSE_P) (T_AT qident)?
;

copy_from_local_stmt : // COPY FROM LOCAL statement
T_COPY T_FROM T_LOCAL copy_source (T_COMMA copy_source)* T_TO copy_target copy_file_option*
;


copy_stmt : // COPY statement
T_COPY (table_name | T_OPEN_P select_stmt T_CLOSE_P) T_TO T_HDFS? copy_target copy_option*
;

copy_source :
(file_name | expr)
;

copy_target :
(file_name | expr)
Expand All @@ -666,12 +655,6 @@ copy_option :
| T_SQLINSERT qident
;

copy_file_option :
T_DELETE
| T_IGNORE
| T_OVERWRITE
;

commit_stmt : // COMMIT statement
T_COMMIT T_WORK?
;
Expand Down Expand Up @@ -1195,30 +1178,7 @@ expr_file :
file_name
| expr
;

hive :
T_HIVE hive_item*
;

hive_item :
T_SUB qident expr
| T_SUB qident L_ID T_EQUAL expr
| T_SUB qident
;

host :
'!' host_cmd ';' // OS command
| host_stmt
;

host_cmd :
.*?
;

host_stmt :
T_HOST expr
;

file_name :
L_FILE | ('/' | '.' '/')? qident ('/' qident)*
;
Expand Down Expand Up @@ -1395,8 +1355,6 @@ non_reserved_words : // Tokens that are not reserved words
| T_HASH
| T_HAVING
| T_HDFS
| T_HIVE
| T_HOST
| T_IDENTITY
| T_IF
| T_IGNORE
Expand Down Expand Up @@ -1718,9 +1676,7 @@ T_GROUP : G R O U P ;
T_HANDLER : H A N D L E R ;
T_HASH : H A S H ;
T_HAVING : H A V I N G ;
T_HDFS : H D F S ;
T_HIVE : H I V E ;
T_HOST : H O S T ;
T_HDFS : H D F S ;
T_IDENTITY : I D E N T I T Y ;
T_IF : I F ;
T_IGNORE : I G N O R E ;
Expand Down
145 changes: 0 additions & 145 deletions hplsql/src/main/java/org/apache/hive/hplsql/Copy.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,133 +261,6 @@ else if (sqlInsert) {
}
}

/**
* Run COPY FROM LOCAL statement
*/
public Integer runFromLocal(HplsqlParser.Copy_from_local_stmtContext ctx) {
trace(ctx, "COPY FROM LOCAL");
initFileOptions(ctx.copy_file_option());
HashMap<String, Pair<String, Long>> srcFiles = new HashMap<>();
String src = evalPop(ctx.copy_source(0)).toString();
String dest = evalPop(ctx.copy_target()).toString();
int srcItems = ctx.copy_source().size();
for (int i = 0; i < srcItems; i++) {
createLocalFileList(srcFiles, evalPop(ctx.copy_source(i)).toString(), null);
}
if (info) {
info(ctx, "Files to copy: " + srcFiles.size() + " (" + Utils.formatSizeInBytes(srcSizeInBytes) + ")");
}
if (srcFiles.size() == 0) {
exec.setHostCode(2);
return 2;
}
timer.start();
File file = new File();
FileSystem fs;
int succeed = 0;
int failed = 0;
long copiedSize = 0;
try {
fs = file.createFs();
boolean multi = false;
if (srcFiles.size() > 1) {
multi = true;
}
for (Map.Entry<String, Pair<String, Long>> i : srcFiles.entrySet()) {
try {
Path s = new Path(i.getKey());
Path d;
if (multi) {
String relativePath = i.getValue().getLeft();
if (relativePath == null) {
d = new Path(dest, s.getName());
}
else {
d = new Path(dest, relativePath + Path.SEPARATOR + s.getName());
}
}
else {
// Path to file is specified (can be relative), so treat target as a file name (hadoop fs -put behavior)
if (srcItems == 1 && i.getKey().endsWith(src)) {
d = new Path(dest);
}
// Source directory is specified, so treat the target as a directory
else {
d = new Path(dest + Path.SEPARATOR + s.getName());
}
}
fs.copyFromLocalFile(delete, overwrite, s, d);
succeed++;
long size = i.getValue().getRight();
copiedSize += size;
if (info) {
info(ctx, "Copied: " + file.resolvePath(d) + " (" + Utils.formatSizeInBytes(size) + ")");
}
}
catch(IOException e) {
failed++;
if (!ignore) {
throw e;
}
}
}
}
catch(IOException e) {
exec.signal(e);
exec.setHostCode(1);
return 1;
}
finally {
long elapsed = timer.stop();
if (info) {
info(ctx, "COPY completed: " + succeed + " succeed, " + failed + " failed, " +
timer.format() + ", " + Utils.formatSizeInBytes(copiedSize) + ", " +
Utils.formatBytesPerSec(copiedSize, elapsed));
}
if (failed == 0) {
exec.setHostCode(0);
}
else {
exec.setHostCode(1);
}
file.close();
}
return 0;
}

/**
* Create the list of local files for the specified path (including subdirectories)
*/
void createLocalFileList(HashMap<String, Pair<String, Long>> list, String path, String relativePath) {
java.io.File file = new java.io.File(path);
if (file.exists()) {
if (file.isDirectory()) {
for (java.io.File i : file.listFiles()) {
if (i.isDirectory()) {
String rel;
if (relativePath == null) {
rel = i.getName();
}
else {
rel = relativePath + java.io.File.separator + i.getName();
}
createLocalFileList(list, i.getAbsolutePath(), rel);
}
else {
long size = i.length();
list.put(i.getAbsolutePath(), Pair.of(relativePath, size));
srcSizeInBytes += size;
}
}
}
else {
long size = file.length();
list.put(file.getAbsolutePath(), Pair.of(relativePath, size));
srcSizeInBytes += size;
}
}
}

/**
* Initialize COPY command options
*/
Expand Down Expand Up @@ -419,24 +292,6 @@ else if (option.T_BATCHSIZE() != null) {
}
}
}

/**
* Initialize COPY FILE options
*/
void initFileOptions(List<HplsqlParser.Copy_file_optionContext> options) {
srcSizeInBytes = 0;
for (HplsqlParser.Copy_file_optionContext i : options) {
if (i.T_OVERWRITE() != null) {
overwrite = true;
}
else if (i.T_DELETE() != null) {
delete = true;
}
else if (i.T_IGNORE() != null) {
ignore = true;
}
}
}

/**
* Evaluate the expression and pop value from the stack
Expand Down
Loading
Loading