Skip to content
This repository was archived by the owner on Jul 9, 2021. It is now read-only.

SQOOP-3433: Improve Error Message if No User Mapping Found #76

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
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
23 changes: 11 additions & 12 deletions src/java/org/apache/sqoop/hive/TableDefWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Properties;
import java.util.Set;

import org.apache.avro.Schema;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -151,19 +154,15 @@ public String getCreateTableStmt() throws IOException {
sb.append(outputTableName).append("` ( ");

// Check that all explicitly mapped columns are present in result set
for(Object column : userMapping.keySet()) {
boolean found = false;
for(String c : colNames) {
if (c.equals(column)) {
found = true;
break;
}
}
final Set<Object> userMappingKeys = new LinkedHashSet<>(userMapping.keySet());
final List<String> colNamesSet = Arrays.asList(colNames);

if (!found) {
throw new IllegalArgumentException("No column by the name " + column
+ "found while importing data");
}
userMappingKeys.removeAll(colNamesSet);

if (!userMappingKeys.isEmpty()) {
throw new IllegalArgumentException(
"No user mappings found for columns " + userMappingKeys
+ " while importing data");
}

boolean first = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void testHiveImportAsParquetWithMapColumnHiveAndOriginalColumnNameFails()
.build();

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("No column by the name C2#INTEGERfound while importing data");
expectedException.expectMessage("No user mappings found for columns [C2#INTEGER] while importing data");

runImportThrowingException(args);
}
Expand Down