Skip to content
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

Merged
merged 13 commits into from
Apr 16, 2024

Conversation

zachjsh
Copy link
Contributor

@zachjsh zachjsh commented Apr 1, 2024

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:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

catch (Types.IncompatibleTypeException e) {
incompatible = true;
}
if (incompatible) {
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, fixed.

Comment on lines 479 to 494
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()
);
}
}
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, fixed

@zachjsh zachjsh requested a review from kgyrtkirk April 16, 2024 19:45
Copy link
Contributor

@abhishekrb19 abhishekrb19 left a 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)
Copy link
Contributor

@abhishekrb19 abhishekrb19 Apr 16, 2024

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):

Suggested 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo:

Suggested change
public void testInsertNoPartitonedByFromCatalog()
public void testErrorWhenNoPartitionedBy()

* value from the catalog.
*/
@Test
public void testInsertHourGrainPartitonedByFromCatalog()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo:

Suggested change
public void testInsertHourGrainPartitonedByFromCatalog()
public void testUsePartitionedByFromCatalog()

* the query value is used.
*/
@Test
public void testInsertHourGrainWithDayPartitonedByFromQuery()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void testInsertHourGrainWithDayPartitonedByFromQuery()
public void testUsePartitionedByFromQuery()

* the query value is used.
*/
@Test
public void testInsertNoPartitonedByWithDayPartitonedByFromQuery()
Copy link
Contributor

@abhishekrb19 abhishekrb19 Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void testInsertNoPartitonedByWithDayPartitonedByFromQuery()
public void testUsePartitionedByFromQuery()

@zachjsh zachjsh merged commit a5428e7 into apache:master Apr 16, 2024
85 checks passed
@zachjsh zachjsh deleted the validate-catalog-complex-columns branch April 16, 2024 21:20
@adarshsanjeev adarshsanjeev added this to the 30.0.0 milestone May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants