Skip to content

Raise error of mismatch column name (when matching_by_column_name is enabled) #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
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
15 changes: 14 additions & 1 deletion src/main/java/org/embulk/output/SnowflakeOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,32 @@ protected void doBegin(
matchByColumnName == SnowflakePluginTask.MatchByColumnName.CASE_SENSITIVE
? String::equals
: String::equalsIgnoreCase;

List<String> invalidSchemaColumnNames = new ArrayList<>();

int columnNumber = 1;
for (int i = 0; i < targetTableSchema.getCount(); i++) {
JdbcColumn targetColumn = targetTableSchema.getColumn(i);
Column schemaColumn = schema.getColumn(i);
if (targetColumn.isSkipColumn()) {
invalidSchemaColumnNames.add(schemaColumn.getName());
continue;
}
Column schemaColumn = schema.getColumn(i);
if (compare.apply(schemaColumn.getName(), targetColumn.getName())) {
copyIntoTableColumnNames.add(targetColumn.getName());
copyIntoCSVColumnNumbers.add(columnNumber);
} else {
invalidSchemaColumnNames.add(schemaColumn.getName());
}
columnNumber += 1;
}
if (!invalidSchemaColumnNames.isEmpty()) {
String msg =
String.format(
"input schema column %s is not found in target table.",
String.join(", ", invalidSchemaColumnNames));
throw new UnsupportedOperationException(msg);
}
pluginTask.setCopyIntoTableColumnNames(copyIntoTableColumnNames.toArray(new String[0]));
pluginTask.setCopyIntoCSVColumnNumbers(
copyIntoCSVColumnNumbers.stream().mapToInt(i -> i).toArray());
Expand Down
Loading