Skip to content

Commit

Permalink
CDPD-45438: [Importer] Add a regex for column name validation in table (
Browse files Browse the repository at this point in the history
#3530)

(cherry picked from commit 8685078)
(cherry picked from commit 417d9a8)
Change-Id: I04c4e5e2f88a2938c6a515565e6906ef2f2d8547
(cherry picked from commit e9eba9b40315abe09165e76e56db4f1244ffcb57)
  • Loading branch information
agl29 authored and wing2fly committed Nov 8, 2023
1 parent 4cb75a8 commit daca021
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions desktop/libs/indexer/src/indexer/templates/importer.mako
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
<script type="text/html" id="table-field-template">
<div>
<label data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">${ _('Name') }&nbsp;
<input data-hue-analytics="importer:field-name-click" type="text" class="input-large" placeholder="${ _('Field name') }" required data-bind="textInput: name" pattern="[a-zA-Z0-9_]+$" title="${ _('Only alphanumeric and underscore characters') }">
<input data-hue-analytics="importer:field-name-click" type="text" class="input-large" placeholder="${ _('Field name') }" required data-bind="textInput: name, attr: { pattern: $root.createWizard.source.columnNamePattern, title: $root.createWizard.source.columnNameAllowedCharacters() }">
</label>
<label class="margin-left-5">${ _('Type') }&nbsp;
Expand Down Expand Up @@ -1532,6 +1532,14 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
return "new_field_" + fieldNum
};
var getColumnNameValidationRegex = function (sourceType) {
if (sourceType === 'hive') {
return "^[a-zA-Z0-9_ ]+$";
} else {
return "^[a-zA-Z0-9_]+$";
}
};
var createDefaultField = function () {
var defaultField = ko.mapping.fromJS(${default_field_type | n});
Expand Down Expand Up @@ -1843,6 +1851,8 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
}
return self.inputFormatsAll();
});
self.columnNamePattern = getColumnNameValidationRegex(vm.sourceType);
self.columnNameAllowedCharacters = ko.observable(vm.sourceType === 'hive' ? _('Only alphanumeric, underscore and space characters') : _('Only alphanumeric and underscore characters') );
self.interpreters = ko.pureComputed(function() {
return window.getLastKnownConfig().app_config.editor.interpreters.filter(function (interpreter) { return interpreter.is_sql && interpreter.dialect != 'phoenix' });
Expand Down Expand Up @@ -2830,6 +2840,10 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
});
self.readyToIndex = ko.pureComputed(function () {
var validFields = self.destination.columns().length || self.destination.outputFormat() === 'database';
var isValidColumnNames = self.destination.columns().every(function (column) {
return RegExp(getColumnNameValidationRegex(vm.sourceType)).test(column.name());
});
var validTableColumns = self.destination.outputFormat() !== 'table' || ($.grep(self.destination.columns(), function(column) {
return column.name().length === 0;
}).length === 0
Expand Down Expand Up @@ -2862,7 +2876,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
}).length === 0
) || self.destination.indexerConfigSet();
return self.isValidDestination() && validFields && validTableColumns && validIndexFields && isTargetAlreadyExisting && isValidTable;
return self.isValidDestination() && validFields && validTableColumns && validIndexFields && isTargetAlreadyExisting && isValidTable && isValidColumnNames;
});
self.formatTypeSubscribed = false;
Expand Down

0 comments on commit daca021

Please sign in to comment.