Skip to content

Commit

Permalink
Force column names to take precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Jun 24, 2024
1 parent 3d211fc commit c87ba9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public synchronized void init(
final Map<String, Object> queryScopeVariables = compilationProcessor.getQueryScopeVariables();
final ColumnTypeConvertor convertor = ColumnTypeConvertorFactory.getConvertor(column.getDataType());
for (String strValue : strValues) {
convertor.convertValue(column, strValue, queryScopeVariables, valueList::add);
convertor.convertValue(column, tableDefinition, strValue, queryScopeVariables, valueList::add);
}
values = valueList.toArray();
} catch (final RuntimeException err) {
Expand Down Expand Up @@ -337,9 +337,17 @@ Object convertParamValue(Object paramValue) {
*/
final boolean convertValue(
@NotNull final ColumnDefinition<?> column,
@NotNull final TableDefinition tableDefinition,
@NotNull final String strValue,
@NotNull final Map<String, Object> queryScopeVariables,
@NotNull final Consumer<Object> valueConsumer) {
if (tableDefinition.getColumn(strValue) != null) {
// this is also a column name which needs to take precedence, and we can't convert it
throw new IllegalArgumentException(String.format(
"Failed to convert literal value <%s> for column \"%s\" of type %s; it is a column name",
strValue, column.getName(), column.getDataType().getName()));
}

if (queryScopeVariables.containsKey(strValue)) {
Object paramValue = queryScopeVariables.get(strValue);
if (paramValue != null && paramValue.getClass().isArray()) {
Expand All @@ -358,12 +366,15 @@ final boolean convertValue(
valueConsumer.accept(convertParamValue(paramValue));
return false;
}

try {
valueConsumer.accept(convertStringLiteral(strValue));
} catch (Throwable t) {
throw new IllegalArgumentException("Failed to convert literal value <" + strValue +
"> for column \"" + column.getName() + "\" of type " + column.getDataType().getName(), t);
throw new IllegalArgumentException(String.format(
"Failed to convert literal value <%s> for column \"%s\" of type %s",
strValue, column.getName(), column.getDataType().getName()), t);
}

return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public void init(

try {
boolean wasAnArrayType = convertor.convertValue(
def, value, compilationProcessor.getQueryScopeVariables(), realValue::setValue);
def, tableDefinition, value, compilationProcessor.getQueryScopeVariables(),
realValue::setValue);
if (wasAnArrayType) {
conversionError =
new IllegalArgumentException("RangeFilter does not support array types for column "
Expand Down

0 comments on commit c87ba9a

Please sign in to comment.