-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support fetching queries to be verified using a Presto query
Currently, we support fetch source queries (pairs for queries to be verified) from an MySQL table by a given suite. This is insufficient in some cases, as it requires MySQL and is also bound by the limitation of MySQL. Add support to fetch source queries by running a Presto query. The fetching query will be run on the helper cluster.
- Loading branch information
1 parent
6a763b2
commit 2e179d3
Showing
9 changed files
with
435 additions
and
3 deletions.
There are no files selected for viewing
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
94 changes: 94 additions & 0 deletions
94
...ifier/src/main/java/com/facebook/presto/verifier/source/PrestoQuerySourceQueryConfig.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,94 @@ | ||
/* | ||
* 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.source; | ||
|
||
import com.facebook.airlift.configuration.Config; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import java.util.Optional; | ||
|
||
public class PrestoQuerySourceQueryConfig | ||
{ | ||
private String query; | ||
private String catalog; | ||
private String schema; | ||
private Optional<String> username = Optional.empty(); | ||
private Optional<String> password = Optional.empty(); | ||
|
||
@NotNull | ||
public String getQuery() | ||
{ | ||
return query; | ||
} | ||
|
||
@Config("query") | ||
public PrestoQuerySourceQueryConfig setQuery(String query) | ||
{ | ||
this.query = query; | ||
return this; | ||
} | ||
|
||
@NotNull | ||
public String getCatalog() | ||
{ | ||
return catalog; | ||
} | ||
|
||
@Config("catalog") | ||
public PrestoQuerySourceQueryConfig setCatalog(String catalog) | ||
{ | ||
this.catalog = catalog; | ||
return this; | ||
} | ||
|
||
@NotNull | ||
public String getSchema() | ||
{ | ||
return schema; | ||
} | ||
|
||
@Config("schema") | ||
public PrestoQuerySourceQueryConfig setSchema(String schema) | ||
{ | ||
this.schema = schema; | ||
return this; | ||
} | ||
|
||
@NotNull | ||
public Optional<String> getUsername() | ||
{ | ||
return username; | ||
} | ||
|
||
@Config("username") | ||
public PrestoQuerySourceQueryConfig setUsername(String username) | ||
{ | ||
this.username = Optional.ofNullable(username); | ||
return this; | ||
} | ||
|
||
@NotNull | ||
public Optional<String> getPassword() | ||
{ | ||
return password; | ||
} | ||
|
||
@Config("password") | ||
public PrestoQuerySourceQueryConfig setPassword(String password) | ||
{ | ||
this.password = Optional.ofNullable(password); | ||
return this; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...ier/src/main/java/com/facebook/presto/verifier/source/PrestoQuerySourceQuerySupplier.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,81 @@ | ||
/* | ||
* 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.source; | ||
|
||
import com.facebook.presto.sql.parser.SqlParser; | ||
import com.facebook.presto.verifier.annotation.ForHelper; | ||
import com.facebook.presto.verifier.framework.QueryConfiguration; | ||
import com.facebook.presto.verifier.framework.SourceQuery; | ||
import com.facebook.presto.verifier.framework.VerificationContext; | ||
import com.facebook.presto.verifier.prestoaction.PrestoAction; | ||
import com.facebook.presto.verifier.prestoaction.PrestoAction.ResultSetConverter; | ||
import com.facebook.presto.verifier.prestoaction.PrestoActionFactory; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.facebook.presto.verifier.framework.QueryStage.SOURCE; | ||
import static com.facebook.presto.verifier.framework.VerifierUtil.PARSING_OPTIONS; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class PrestoQuerySourceQuerySupplier | ||
implements SourceQuerySupplier | ||
{ | ||
public static final String PRESTO_QUERY_SOURCE_QUERY_SUPPLIER = "presto-query"; | ||
private static final ResultSetConverter<SourceQuery> SOURCE_QUERY_CONVERTER = resultSet -> | ||
Optional.of(new SourceQuery( | ||
resultSet.getString("suite"), | ||
resultSet.getString("name"), | ||
resultSet.getString("control_query"), | ||
resultSet.getString("test_query"), | ||
new QueryConfiguration( | ||
resultSet.getString("control_catalog"), | ||
resultSet.getString("control_schema"), | ||
Optional.ofNullable(resultSet.getString("control_username")), | ||
Optional.ofNullable(resultSet.getString("control_password")), | ||
Optional.ofNullable(resultSet.getString("control_session_properties")) | ||
.map(StringToStringMapColumnMapper.CODEC::fromJson)), | ||
new QueryConfiguration( | ||
resultSet.getString("test_catalog"), | ||
resultSet.getString("test_schema"), | ||
Optional.ofNullable(resultSet.getString("test_username")), | ||
Optional.ofNullable(resultSet.getString("test_password")), | ||
Optional.ofNullable(resultSet.getString("test_session_properties")) | ||
.map(StringToStringMapColumnMapper.CODEC::fromJson)))); | ||
|
||
private final PrestoAction helperAction; | ||
private final SqlParser sqlParser; | ||
private final String query; | ||
|
||
@Inject | ||
public PrestoQuerySourceQuerySupplier( | ||
@ForHelper PrestoActionFactory helperActionFactory, | ||
SqlParser sqlParser, | ||
PrestoQuerySourceQueryConfig config) | ||
{ | ||
this.helperAction = helperActionFactory.create( | ||
new QueryConfiguration(config.getCatalog(), config.getSchema(), config.getUsername(), config.getPassword(), Optional.empty()), | ||
VerificationContext.create("", "")); | ||
this.sqlParser = requireNonNull(sqlParser, "sqlParser is null"); | ||
this.query = requireNonNull(config.getQuery(), "query is null"); | ||
} | ||
|
||
@Override | ||
public List<SourceQuery> get() | ||
{ | ||
return helperAction.execute(sqlParser.createStatement(query, PARSING_OPTIONS), SOURCE, SOURCE_QUERY_CONVERTER).getResults(); | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
...r/src/test/java/com/facebook/presto/verifier/source/TestPrestoQuerySourceQueryConfig.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,57 @@ | ||
/* | ||
* 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.source; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static com.facebook.airlift.configuration.testing.ConfigAssertions.assertFullMapping; | ||
import static com.facebook.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; | ||
import static com.facebook.airlift.configuration.testing.ConfigAssertions.recordDefaults; | ||
|
||
public class TestPrestoQuerySourceQueryConfig | ||
{ | ||
@Test | ||
public void testDefault() | ||
{ | ||
assertRecordedDefaults(recordDefaults(PrestoQuerySourceQueryConfig.class) | ||
.setQuery(null) | ||
.setCatalog(null) | ||
.setSchema(null) | ||
.setUsername(null) | ||
.setPassword(null)); | ||
} | ||
|
||
@Test | ||
public void testExplicitPropertyMappings() | ||
{ | ||
Map<String, String> properties = new ImmutableMap.Builder<String, String>() | ||
.put("query", "SELECT query") | ||
.put("catalog", "test_catalog") | ||
.put("schema", "test_schema") | ||
.put("username", "test_user") | ||
.put("password", "test_password") | ||
.build(); | ||
PrestoQuerySourceQueryConfig expected = new PrestoQuerySourceQueryConfig() | ||
.setQuery("SELECT query") | ||
.setCatalog("test_catalog") | ||
.setSchema("test_schema") | ||
.setUsername("test_user") | ||
.setPassword("test_password"); | ||
|
||
assertFullMapping(properties, expected); | ||
} | ||
} |
Oops, something went wrong.