-
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
Move INSERT & REPLACE validation to the Calcite validator #15908
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0dc3c5a
ingestHandlers validate sqlNode as DruidSqlIngest instead of the sele…
zachjsh 6579bd8
* remove dead code
zachjsh e019b70
* fix failing tests, remove some uneeded validations that are done el…
zachjsh 2565173
* fix static check
zachjsh d2f0e47
* remove uneeded ValidatorContext
zachjsh b475ecc
* resolve getEffectiveGranularity comment
zachjsh cad940d
* remove duplicate validation being done in DruidSqlValidator and Ing…
zachjsh 50061d6
* simplify SqlInsert source query conversion
zachjsh 12c3d60
* remove redundant comments
zachjsh 3836330
* add tests for catalog provided segment granularity
zachjsh eca4be2
Merge remote-tracking branch 'apache/master' into validate-sqlInsert-…
zachjsh 914553f
* remove uneeded comments
zachjsh 9328165
Merge remote-tracking branch 'apache/master' into validate-sqlInsert-…
zachjsh 0608676
* fix exportFileFormat issue
zachjsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
...s-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogIngestionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.catalog.sql; | ||
|
||
import org.apache.druid.catalog.CatalogException; | ||
import org.apache.druid.catalog.model.Columns; | ||
import org.apache.druid.catalog.model.TableMetadata; | ||
import org.apache.druid.catalog.model.table.TableBuilder; | ||
import org.apache.druid.catalog.storage.CatalogStorage; | ||
import org.apache.druid.catalog.storage.CatalogTests; | ||
import org.apache.druid.catalog.sync.CachedMetadataCatalog; | ||
import org.apache.druid.catalog.sync.MetadataCatalog; | ||
import org.apache.druid.java.util.common.granularity.Granularities; | ||
import org.apache.druid.metadata.TestDerbyConnector; | ||
import org.apache.druid.segment.column.ColumnType; | ||
import org.apache.druid.segment.column.RowSignature; | ||
import org.apache.druid.sql.calcite.CalciteIngestionDmlTest; | ||
import org.apache.druid.sql.calcite.filtration.Filtration; | ||
import org.apache.druid.sql.calcite.planner.CatalogResolver; | ||
import org.apache.druid.sql.calcite.util.CalciteTests; | ||
import org.apache.druid.sql.calcite.util.SqlTestFramework; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
/** | ||
* Test the use of catalog specs to drive MSQ ingestion. | ||
*/ | ||
public class CatalogIngestionTest extends CalciteIngestionDmlTest | ||
{ | ||
@ClassRule | ||
public static final TestDerbyConnector.DerbyConnectorRule DERBY_CONNECTION_RULE = | ||
new TestDerbyConnector.DerbyConnectorRule(); | ||
|
||
/** | ||
* Signature for the foo datasource after applying catalog metadata. | ||
*/ | ||
private static final RowSignature FOO_SIGNATURE = RowSignature.builder() | ||
.add("__time", ColumnType.LONG) | ||
.add("extra1", ColumnType.STRING) | ||
.add("dim2", ColumnType.STRING) | ||
.add("dim1", ColumnType.STRING) | ||
.add("cnt", ColumnType.LONG) | ||
.add("m1", ColumnType.DOUBLE) | ||
.add("extra2", ColumnType.LONG) | ||
.add("extra3", ColumnType.STRING) | ||
.add("m2", ColumnType.DOUBLE) | ||
.build(); | ||
|
||
private static CatalogStorage storage; | ||
|
||
@Override | ||
public CatalogResolver createCatalogResolver() | ||
{ | ||
CatalogTests.DbFixture dbFixture = new CatalogTests.DbFixture(DERBY_CONNECTION_RULE); | ||
storage = dbFixture.storage; | ||
MetadataCatalog catalog = new CachedMetadataCatalog( | ||
storage, | ||
storage.schemaRegistry(), | ||
storage.jsonMapper() | ||
); | ||
return new LiveCatalogResolver(catalog); | ||
} | ||
|
||
@Override | ||
public void finalizeTestFramework(SqlTestFramework sqlTestFramework) | ||
{ | ||
super.finalizeTestFramework(sqlTestFramework); | ||
buildTargetDatasources(); | ||
buildFooDatasource(); | ||
} | ||
|
||
private void buildTargetDatasources() | ||
{ | ||
TableMetadata spec = TableBuilder.datasource("hourDs", "PT1H") | ||
.build(); | ||
createTableMetadata(spec); | ||
} | ||
|
||
public void buildFooDatasource() | ||
{ | ||
TableMetadata spec = TableBuilder.datasource("foo", "ALL") | ||
.timeColumn() | ||
.column("extra1", null) | ||
.column("dim2", null) | ||
.column("dim1", null) | ||
.column("cnt", null) | ||
.column("m1", Columns.DOUBLE) | ||
.column("extra2", Columns.LONG) | ||
.column("extra3", Columns.STRING) | ||
.hiddenColumns(Arrays.asList("dim3", "unique_dim1")) | ||
.sealed(true) | ||
.build(); | ||
createTableMetadata(spec); | ||
} | ||
|
||
private void createTableMetadata(TableMetadata table) | ||
{ | ||
try { | ||
storage.tables().create(table); | ||
} | ||
catch (CatalogException e) { | ||
fail(e.getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* If the segment grain is given in the catalog then use this value is used. | ||
*/ | ||
@Test | ||
public void testInsertHourGrain() | ||
{ | ||
testIngestionQuery() | ||
.sql("INSERT INTO hourDs\n" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a follow up, could you also please add a test for a |
||
"SELECT * FROM foo") | ||
.authentication(CalciteTests.SUPER_USER_AUTH_RESULT) | ||
.expectTarget("hourDs", FOO_SIGNATURE) | ||
.expectResources(dataSourceWrite("hourDs"), dataSourceRead("foo")) | ||
.expectQuery( | ||
newScanQueryBuilder() | ||
.dataSource("foo") | ||
.intervals(querySegmentSpec(Filtration.eternity())) | ||
.columns("__time", "cnt", "dim1", "dim2", "extra1", "extra2", "extra3", "m1", "m2") | ||
.context(queryContextWithGranularity(Granularities.HOUR)) | ||
.build() | ||
) | ||
.verify(); | ||
} | ||
|
||
/** | ||
* If the segment grain is given in the catalog, and also by PARTITIONED BY, then | ||
* the query value is used. | ||
*/ | ||
@Test | ||
public void testInsertHourGrainWithDay() | ||
{ | ||
testIngestionQuery() | ||
.sql("INSERT INTO hourDs\n" + | ||
"SELECT * FROM foo\n" + | ||
"PARTITIONED BY day") | ||
.authentication(CalciteTests.SUPER_USER_AUTH_RESULT) | ||
.expectTarget("hourDs", FOO_SIGNATURE) | ||
.expectResources(dataSourceWrite("hourDs"), dataSourceRead("foo")) | ||
.expectQuery( | ||
newScanQueryBuilder() | ||
.dataSource("foo") | ||
.intervals(querySegmentSpec(Filtration.eternity())) | ||
.columns("__time", "cnt", "dim1", "dim2", "extra1", "extra2", "extra3", "m1", "m2") | ||
.context(queryContextWithGranularity(Granularities.DAY)) | ||
.build() | ||
) | ||
.verify(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.