-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes the connection of Remote HiveServer2 through HiveServer2 JDBC D…
…river (#31573)
- Loading branch information
1 parent
9ce019f
commit 33f65cf
Showing
15 changed files
with
386 additions
and
13 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
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
71 changes: 71 additions & 0 deletions
71
...hardingsphere/infra/database/clickhouse/connector/ClickHouseConnectionPropertiesTest.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,71 @@ | ||
/* | ||
* 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.shardingsphere.infra.database.clickhouse.connector; | ||
|
||
import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; | ||
import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser; | ||
import org.apache.shardingsphere.infra.database.core.exception.UnrecognizedDatabaseURLException; | ||
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; | ||
import org.apache.shardingsphere.infra.database.core.type.DatabaseType; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.apache.shardingsphere.test.util.PropertiesBuilder; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
|
||
import java.util.Properties; | ||
import java.util.stream.Stream; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class ClickHouseConnectionPropertiesTest { | ||
|
||
private final ConnectionPropertiesParser parser = DatabaseTypedSPILoader.getService(ConnectionPropertiesParser.class, TypedSPILoader.getService(DatabaseType.class, "ClickHouse")); | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@ArgumentsSource(NewConstructorTestCaseArgumentsProvider.class) | ||
void assertNewConstructor(final String name, final String url, final String hostname, final int port, final String catalog, final String schema, final Properties queryProps) { | ||
ConnectionProperties actual = parser.parse(url, null, null); | ||
assertThat(actual.getHostname(), is(hostname)); | ||
assertThat(actual.getPort(), is(port)); | ||
assertThat(actual.getCatalog(), is(catalog)); | ||
assertThat(actual.getSchema(), is(schema)); | ||
assertThat(actual.getQueryProperties(), is(queryProps)); | ||
} | ||
|
||
@Test | ||
void assertNewConstructorFailure() { | ||
assertThrows(UnrecognizedDatabaseURLException.class, () -> parser.parse("jdbc:ch:xxxxxxxx", null, null)); | ||
} | ||
|
||
private static class NewConstructorTestCaseArgumentsProvider implements ArgumentsProvider { | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) { | ||
return Stream.of( | ||
Arguments.of("simple", "jdbc:ch://127.0.0.1/foo_ds", "127.0.0.1", 8123, "foo_ds", null, new Properties()), | ||
Arguments.of("complex", "jdbc:clickhouse:http://127.0.0.1:9999/foo_ds?continueBatchOnError=true", "127.0.0.1", 9999, "foo_ds", null, | ||
PropertiesBuilder.build(new PropertiesBuilder.Property("continueBatchOnError", "true")))); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ingsphere/infra/database/clickhouse/metadata/database/ClickHouseDatabaseMetaDataTest.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,44 @@ | ||
/* | ||
* 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.shardingsphere.infra.database.clickhouse.metadata.database; | ||
|
||
import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; | ||
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; | ||
import org.apache.shardingsphere.infra.database.core.type.DatabaseType; | ||
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class ClickHouseDatabaseMetaDataTest { | ||
|
||
private final DialectDatabaseMetaData dialectDatabaseMetaData = DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class, TypedSPILoader.getService(DatabaseType.class, "ClickHouse")); | ||
|
||
@Test | ||
void assertGetQuoteCharacter() { | ||
assertThat(dialectDatabaseMetaData.getQuoteCharacter(), is(QuoteCharacter.QUOTE)); | ||
} | ||
|
||
@Test | ||
void assertGetDefaultNullsOrderType() { | ||
assertThat(dialectDatabaseMetaData.getDefaultNullsOrderType(), is(NullsOrderType.FIRST)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...g/apache/shardingsphere/infra/database/hive/connector/HiveConnectionPropertiesParser.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,49 @@ | ||
/* | ||
* 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.shardingsphere.infra.database.hive.connector; | ||
|
||
import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; | ||
import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser; | ||
import org.apache.shardingsphere.infra.database.core.connector.StandardConnectionProperties; | ||
import org.apache.shardingsphere.infra.database.core.connector.url.JdbcUrl; | ||
import org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcUrlParser; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Connection properties parser of Hive. | ||
*/ | ||
public final class HiveConnectionPropertiesParser implements ConnectionPropertiesParser { | ||
|
||
private static final int DEFAULT_PORT = 10000; | ||
|
||
private static final String DEFAULT_HOSTNAME = "localhost"; | ||
|
||
@Override | ||
public ConnectionProperties parse(final String url, final String username, final String catalog) { | ||
JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(url); | ||
return jdbcUrl.getHostname().isEmpty() | ||
? new StandardConnectionProperties(DEFAULT_HOSTNAME, jdbcUrl.getPort(DEFAULT_PORT), jdbcUrl.getDatabase(), null, jdbcUrl.getQueryProperties(), new Properties()) | ||
: new StandardConnectionProperties(jdbcUrl.getHostname(), jdbcUrl.getPort(DEFAULT_PORT), jdbcUrl.getDatabase(), null, jdbcUrl.getQueryProperties(), new Properties()); | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "Hive"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...org/apache/shardingsphere/infra/database/hive/metadata/database/HiveDatabaseMetaData.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,43 @@ | ||
/* | ||
* 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.shardingsphere.infra.database.hive.metadata.database; | ||
|
||
import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; | ||
|
||
/** | ||
* Database metadata of Hive. | ||
*/ | ||
public final class HiveDatabaseMetaData implements DialectDatabaseMetaData { | ||
|
||
@Override | ||
public QuoteCharacter getQuoteCharacter() { | ||
return QuoteCharacter.QUOTE; | ||
} | ||
|
||
@Override | ||
public NullsOrderType getDefaultNullsOrderType() { | ||
return NullsOrderType.FIRST; | ||
} | ||
|
||
@Override | ||
public String getDatabaseType() { | ||
return "Hive"; | ||
} | ||
} |
Oops, something went wrong.