-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
INSERT/REPLACE complex target column types are validated against source input expressions #16223
INSERT/REPLACE complex target column types are validated against source input expressions #16223
Conversation
catch (Types.IncompatibleTypeException e) { | ||
incompatible = true; | ||
} | ||
if (incompatible) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- throw a
Types.IncompatibleTypeException
exception based on the result of equals - you could place these things inside the
catch
- remove the
incompatible
boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, fixed.
RelDataType relType; | ||
if (sqlTypeName != null) { | ||
relType = typeFactory.createSqlType(sqlTypeName); | ||
} else { | ||
fields.add(Pair.of( | ||
colName, | ||
typeFactory.createTypeWithNullability(relType, true) | ||
)); | ||
ColumnType columnType = ColumnType.fromString(definedCol.sqlStorageType()); | ||
if (columnType != null && columnType.getType().equals(ValueType.COMPLEX)) { | ||
relType = RowSignatures.makeComplexType(typeFactory, columnType, sourceField.getType().isNullable()); | ||
} else { | ||
relType = RowSignatures.columnTypeToRelDataType( | ||
typeFactory, | ||
columnType, | ||
// this nullability is ignored for complex types for some reason, hence the check for complex above. | ||
sourceField.getType().isNullable() | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to me that it tries to compute the RelDataType
for definedCol
; can we have method or something for that? maybe that could even make it easier to write more direct tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, fixed
...nsions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogReplaceTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Left a few suggestions that can be done in a follow up.
.authentication(CalciteTests.SUPER_USER_AUTH_RESULT) | ||
.expectValidationError( | ||
DruidException.class, | ||
StringUtils.format("Operation [%s] requires a PARTITIONED BY to be explicitly defined, but none was found.", operationName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps be more explicit in the error message (the actual code also needs to change):
StringUtils.format("Operation [%s] requires a PARTITIONED BY to be explicitly defined, but none was found.", operationName) | |
StringUtils.format("Operation [%s] requires a PARTITIONED BY clause to be explicitly defined in the query or the catalog, but none was found.", operationName) |
* validation error. | ||
*/ | ||
@Test | ||
public void testInsertNoPartitonedByFromCatalog() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
public void testInsertNoPartitonedByFromCatalog() | |
public void testErrorWhenNoPartitionedBy() |
* value from the catalog. | ||
*/ | ||
@Test | ||
public void testInsertHourGrainPartitonedByFromCatalog() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
public void testInsertHourGrainPartitonedByFromCatalog() | |
public void testUsePartitionedByFromCatalog() |
* the query value is used. | ||
*/ | ||
@Test | ||
public void testInsertHourGrainWithDayPartitonedByFromQuery() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void testInsertHourGrainWithDayPartitonedByFromQuery() | |
public void testUsePartitionedByFromQuery() |
* the query value is used. | ||
*/ | ||
@Test | ||
public void testInsertNoPartitonedByWithDayPartitonedByFromQuery() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void testInsertNoPartitonedByWithDayPartitonedByFromQuery() | |
public void testUsePartitionedByFromQuery() |
Description
This change allows for tables that are defined in the catalog to have their complex defined column types validated against source input expressions mapped to them during DML INSERT/REPLACE operations. The catalog dml unit tests have also been greatly simplified, and a lot of duplicate test code simplified or removed.
This PR has: