-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the target table of the CREATE TABLE statement, run both control and test queries, run SHOW CREATE TABLE query as the check.
- Loading branch information
1 parent
a50fb09
commit 883e883
Showing
6 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...erifier/src/main/java/com/facebook/presto/verifier/framework/CreateTableVerification.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,90 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.verifier.framework; | ||
|
||
import com.facebook.presto.sql.parser.SqlParser; | ||
import com.facebook.presto.sql.tree.CreateTable; | ||
import com.facebook.presto.sql.tree.QualifiedName; | ||
import com.facebook.presto.sql.tree.ShowCreate; | ||
import com.facebook.presto.sql.tree.Statement; | ||
import com.facebook.presto.verifier.prestoaction.PrestoAction.ResultSetConverter; | ||
import com.facebook.presto.verifier.prestoaction.QueryActions; | ||
import com.facebook.presto.verifier.prestoaction.SqlExceptionClassifier; | ||
import com.facebook.presto.verifier.rewrite.QueryRewriter; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import static com.facebook.presto.sql.tree.ShowCreate.Type.TABLE; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class CreateTableVerification | ||
extends DdlVerification<CreateTable> | ||
{ | ||
public static final ResultSetConverter<String> SHOW_CREATE_TABLE_CONVERTER = resultSet -> { | ||
try { | ||
return Optional.of(resultSet.getString("Create Table")); | ||
} | ||
catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
private static final QualifiedName DUMMY_TABLE_NAME = QualifiedName.of("dummy"); | ||
|
||
private final QueryRewriter queryRewriter; | ||
|
||
public CreateTableVerification( | ||
SqlParser sqlParser, | ||
QueryActions queryActions, | ||
SourceQuery sourceQuery, | ||
QueryRewriter queryRewriter, | ||
SqlExceptionClassifier exceptionClassifier, | ||
VerificationContext verificationContext, | ||
VerifierConfig verifierConfig) | ||
{ | ||
super(sqlParser, queryActions, sourceQuery, exceptionClassifier, verificationContext, verifierConfig, SHOW_CREATE_TABLE_CONVERTER); | ||
this.queryRewriter = requireNonNull(queryRewriter, "queryRewriter is null"); | ||
} | ||
|
||
@Override | ||
protected QueryObjectBundle getQueryRewrite(ClusterType clusterType) | ||
{ | ||
return queryRewriter.rewriteQuery(getSourceQuery().getQuery(clusterType), clusterType); | ||
} | ||
|
||
@Override | ||
protected Statement getChecksumQuery(QueryObjectBundle queryBundle) | ||
{ | ||
return new ShowCreate(TABLE, queryBundle.getObjectName()); | ||
} | ||
|
||
@Override | ||
protected boolean match(CreateTable controlObject, CreateTable testObject, QueryObjectBundle control, QueryObjectBundle test) | ||
{ | ||
controlObject = new CreateTable( | ||
DUMMY_TABLE_NAME, | ||
controlObject.getElements(), | ||
controlObject.isNotExists(), | ||
controlObject.getProperties(), | ||
controlObject.getComment()); | ||
testObject = new CreateTable( | ||
DUMMY_TABLE_NAME, | ||
testObject.getElements(), | ||
testObject.isNotExists(), | ||
testObject.getProperties(), | ||
testObject.getComment()); | ||
return Objects.equals(controlObject, testObject); | ||
} | ||
} |
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
128 changes: 128 additions & 0 deletions
128
...ier/src/test/java/com/facebook/presto/verifier/framework/TestCreateTableVerification.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,128 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.verifier.framework; | ||
|
||
import com.facebook.presto.verifier.event.VerifierQueryEvent; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.facebook.presto.verifier.event.VerifierQueryEvent.EventStatus.FAILED; | ||
import static com.facebook.presto.verifier.event.VerifierQueryEvent.EventStatus.SKIPPED; | ||
import static com.facebook.presto.verifier.event.VerifierQueryEvent.EventStatus.SUCCEEDED; | ||
import static com.facebook.presto.verifier.framework.DdlMatchResult.MatchType.CONTROL_NOT_PARSABLE; | ||
import static com.facebook.presto.verifier.framework.DdlMatchResult.MatchType.MATCH; | ||
import static com.facebook.presto.verifier.framework.DdlMatchResult.MatchType.MISMATCH; | ||
import static com.facebook.presto.verifier.framework.DdlMatchResult.MatchType.TEST_NOT_PARSABLE; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
@Test(singleThreaded = true) | ||
public class TestCreateTableVerification | ||
extends AbstractDdlVerificationTest | ||
{ | ||
public TestCreateTableVerification() | ||
throws Exception | ||
{ | ||
} | ||
|
||
@Test | ||
public void testSucceeded() | ||
{ | ||
String query = "CREATE TABLE succeeded (x int, ds varchar) COMMENT 'test table'"; | ||
|
||
Optional<VerifierQueryEvent> event = runVerification(query, query); | ||
assertTrue(event.isPresent()); | ||
assertEvent(event.get(), SUCCEEDED, Optional.of(MATCH), false); | ||
|
||
getQueryRunner().execute("CREATE TABLE like_table (x int, ds varchar)"); | ||
query = "CREATE TABLE succeeded (LIKE like_table INCLUDING PROPERTIES)"; | ||
|
||
event = runVerification(query, query); | ||
assertTrue(event.isPresent()); | ||
System.out.println(event.get().getErrorMessage()); | ||
assertEvent(event.get(), SUCCEEDED, Optional.of(MATCH), false); | ||
|
||
getQueryRunner().execute("DROP TABLE like_table"); | ||
} | ||
|
||
@Test | ||
public void testSucceededExists() | ||
{ | ||
getQueryRunner().execute("CREATE TABLE succeeded_exists (x int, ds varchar)"); | ||
String query = "CREATE TABLE IF NOT EXISTS succeeded_exists (x int, ds varchar)"; | ||
|
||
Optional<VerifierQueryEvent> event = runVerification(query, query); | ||
assertTrue(event.isPresent()); | ||
assertEvent(event.get(), SUCCEEDED, Optional.of(MATCH), false); | ||
|
||
getQueryRunner().execute("DROP TABLE succeeded_exists"); | ||
} | ||
|
||
@Test | ||
public void testControlNotParsable() | ||
{ | ||
String query = "CREATE TABLE control_not_parsable (x int, ds varchar) COMMENT 'test table'"; | ||
MockPrestoAction prestoAction = new MockPrestoAction(ImmutableMap.of(1, "CREATE TABLE succeeded (x int, ds varchar) 'test table'")); | ||
|
||
Optional<VerifierQueryEvent> event = verify(getSourceQuery(query, query), false, prestoAction); | ||
assertTrue(event.isPresent()); | ||
System.out.println(event.get().getErrorMessage()); | ||
assertEvent(event.get(), FAILED, Optional.of(CONTROL_NOT_PARSABLE), false); | ||
} | ||
|
||
@Test | ||
public void testTestNotParsable() | ||
{ | ||
String query = "CREATE TABLE test_not_parsable (x int, ds varchar) COMMENT 'test table'"; | ||
MockPrestoAction prestoAction = new MockPrestoAction(ImmutableMap.of(2, "CREATE TABLE test_not_parsable (x int, ds varchar) 'test table'")); | ||
|
||
Optional<VerifierQueryEvent> event = verify(getSourceQuery(query, query), false, prestoAction); | ||
assertTrue(event.isPresent()); | ||
assertEvent(event.get(), FAILED, Optional.of(TEST_NOT_PARSABLE), false); | ||
} | ||
|
||
@Test | ||
public void testMismatched() | ||
{ | ||
String query = "CREATE TABLE mismatched (x int, ds varchar)"; | ||
MockPrestoAction prestoAction = new MockPrestoAction(ImmutableMap.of( | ||
1, "CREATE TABLE mismatched (x int, ds varchar)", | ||
2, "CREATE TABLE mismatched (ds varchar)")); | ||
|
||
Optional<VerifierQueryEvent> event = verify(getSourceQuery(query, query), false, prestoAction); | ||
assertTrue(event.isPresent()); | ||
assertEvent(event.get(), FAILED, Optional.of(MISMATCH), false); | ||
} | ||
|
||
@Test | ||
public void testSkipped() | ||
{ | ||
Optional<VerifierQueryEvent> event = runVerification( | ||
"CREATE TABLE failed (LIKE non_existing)", | ||
"CREATE TABLE failed (LIKE non_existing)"); | ||
assertTrue(event.isPresent()); | ||
assertEvent(event.get(), SKIPPED, Optional.empty(), false); | ||
} | ||
|
||
@Test | ||
public void testFailed() | ||
{ | ||
Optional<VerifierQueryEvent> event = runVerification( | ||
"CREATE TABLE failed (x int, ds varchar)", | ||
"CREATE TABLE failed (LIKE non_existing)"); | ||
assertTrue(event.isPresent()); | ||
assertEvent(event.get(), FAILED, Optional.empty(), false); | ||
} | ||
} |
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