Skip to content

Commit

Permalink
created shaded all packages and updated examples. (#2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
chernser authored Dec 5, 2024
1 parent 54753c8 commit fdcac72
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 206 deletions.
79 changes: 76 additions & 3 deletions clickhouse-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@
<groupId>${project.parent.groupId}</groupId>
<artifactId>clickhouse-http-client</artifactId>
<version>${revision}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.lz4</groupId>
<artifactId>lz4-pure-java</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -100,7 +97,13 @@
<artifactId>zstd-jni</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>clickhouse-client</artifactId>
Expand Down Expand Up @@ -530,6 +533,76 @@
</filters>
</configuration>
</execution>


<execution>
<id>shade-all-v2</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>shaded-all</shadedClassifierName>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>${shade.base}.google</shadedPattern>
</relocation>
<relocation>
<pattern>io.opencensus</pattern>
<shadedPattern>${shade.base}.opencensus</shadedPattern>
</relocation>
<relocation>
<pattern>io.perfmark</pattern>
<shadedPattern>${shade.base}.perfmark</shadedPattern>
</relocation>
<relocation>
<pattern>net.jpountz</pattern>
<shadedPattern>${shade.base}.jpountz</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>${shade.base}.okio</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>${shade.base}.apache</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Automatic-Module-Name>${project.groupId}.jdbc</Automatic-Module-Name>
<Main-Class>${mainClass}</Main-Class>
<Specification-Title>${spec.title}</Specification-Title>
<Specification-Version>${spec.version}</Specification-Version>
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>google/**</exclude>
<exclude>org/checkerframework/**</exclude>
<exclude>org/codehaus/**</exclude>
<exclude>**/module-info.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
47 changes: 37 additions & 10 deletions client-v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<properties>
<apache.httpclient.version>5.3.1</apache.httpclient.version>
<shade.base>${project.groupId}.shaded</shade.base>
</properties>

<dependencies>
Expand Down Expand Up @@ -157,29 +158,54 @@
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade</id>
<id>shade-all</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<shadedClassifierName>all</shadedClassifierName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>com.clickhouse:clickhouse-data</include>
<include>com.clickhouse:clickhouse-client</include>
<include>org.lz4:lz4-pure-java</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>${shade.base}.org.slf4j</shadedPattern>
</relocation>

<relocation>
<pattern>org.apache</pattern>
<shadedPattern>${shade.base}.org.apache</shadedPattern>
</relocation>

<relocation>
<!-- lz4 -->
<pattern>net.jpountz</pattern>
<shadedPattern>${shade.base}.jpountz</shadedPattern>
<shadedPattern>${shade.base}.net.jpountz.lz4</shadedPattern>
</relocation>

<relocation>
<pattern>org.ow2</pattern>
<shadedPattern>${shade.base}.org.ow2</shadedPattern>
</relocation>

<relocation>
<pattern>com.fasterxml</pattern>
<shadedPattern>${shade.base}.com.fasterxml</shadedPattern>
</relocation>

<relocation>
<pattern>org.roaringbitmap</pattern>
<shadedPattern>${shade.base}.org.roaringbitmap</shadedPattern>
</relocation>

<relocation>
<pattern>org.objectweb</pattern>
<shadedPattern>${shade.base}.org.objectweb</shadedPattern>
</relocation>

</relocations>
<transformers>
<transformer
Expand All @@ -199,6 +225,7 @@
</filters>
</configuration>
</execution>

</executions>
</plugin>
<plugin>
Expand Down
9 changes: 1 addition & 8 deletions examples/client-v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,9 @@
<groupId>com.clickhouse</groupId>
<artifactId>client-v2</artifactId>
<version>${clickhouse-java.version}</version>
<classifier>all</classifier>
</dependency>

<!-- If Old implementation needed -->
<!-- <dependency>-->
<!-- <groupId>com.clickhouse</groupId>-->
<!-- <artifactId>clickhouse-http-client</artifactId>-->
<!-- <version>${clickhouse-java.version}</version>-->
<!-- </dependency>-->


<!-- Recommended for JSON parsing -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-kotlin-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ dependencies {
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")

// https://mvnrepository.com/artifact/com.clickhouse/client-v2
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT")
// implementation("com.clickhouse:client-v2:0.7.1") // release version
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT:all")
// implementation("com.clickhouse:client-v2:0.7.1-patch1:all") // release version

testImplementation("io.ktor:ktor-server-test-host-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ dependencies {

// -- clickhouse dependencies
// Main dependency
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT") // local or nightly build
// implementation("com.clickhouse:client-v2:0.7.1") // release version
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT:all") // local or nightly build
// implementation("com.clickhouse:client-v2:0.7.1-patch1:all") // release version

// -- clickhouse-http-client dependencies if old implementation is needed
// implementation("com.clickhouse:clickhouse-http-client:0.7.1-SNAPSHOT")
Expand Down
13 changes: 2 additions & 11 deletions examples/jdbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ To run simplified example:
mvn exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic"
```

To run example with jdbc-all packaging (fat-jar):
```shell
mvn -Pfatjar exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic"
```

To run example with jdbc-shaded packaging:
```shell
mvn -Pshaded exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic"
```

Addition options can be passed to the application:
- `-DchUrl` - ClickHouse JDBC URL. Default is `jdbc:clickhouse://localhost:8123/default`
- `-DchUrl` - ClickHouse JDBC URL. Default is `jdbc:clickhouse://localhost:8123/default`
- `-Dclickhouse.jdbc.v2=true` - Use JDBC V2 implementation
66 changes: 15 additions & 51 deletions examples/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
</license>
</licenses>

<developers>
<developer>
<id>zhicwu</id>
<name>Zhichun Wu</name>
<email>[email protected]</email>
<timezone>+8</timezone>
</developer>
</developers>

<scm>
<url>https://github.com/ClickHouse/clickhouse-java</url>
<connection>scm:[email protected]:ClickHouse/clickhouse-java.git</connection>
Expand Down Expand Up @@ -73,56 +64,29 @@
<compiler-plugin.version>3.8.1</compiler-plugin.version>

<minJdk>1.8</minJdk>
<clickhouse-packages.classifier>all</clickhouse-packages.classifier>
</properties>

<profiles>
<profile>
<id>http</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>${clickhouse-java.version}</version>
<classifier>http</classifier>
</dependency>
</dependencies>
</profile>

<profile>
<id>shaded</id>
<dependencies>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>${clickhouse-java.version}</version>
<classifier>shaded</classifier>
</dependency>
</dependencies>
</profile>

<profile>
<id>fatjar</id>
<dependencies>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>${clickhouse-java.version}</version>
<classifier>all</classifier>
</dependency>
</dependencies>
</profile>

</profiles>

<dependencies>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${hikaricp.version}</version>
</dependency>

<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>${clickhouse-java.version}</version>
<classifier>${clickhouse-packages.classifier}</classifier>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ static String exteralTables(String url) throws SQLException {
}
}

static String manualTransaction(String url) throws SQLException {
Properties props = new Properties();
// props.setProperty(JdbcConfig.PROP_AUTO_COMMIT, "false");
props.setProperty("autoCommit", "false");
// props.setProperty(JdbcConfig.PROP_TX_SUPPORT, "true");
props.setProperty("transactionSupport", "true");
try (Connection conn = getConnection(url, props)) {
if (!((ClickHouseConnection) conn).isTransactionSupported()) {
System.out.println("Re-establishing connection until transaction is supported...");
return manualTransaction(url);
}

conn.commit();
return "Transaction committed!";
}
}

static String namedParameter(String url) throws SQLException {
Properties props = new Properties();
// props.setProperty(JdbcConfig.PROP_NAMED_PARAM, "true");
Expand Down Expand Up @@ -172,19 +155,14 @@ static String unwrapToUseClientApi(String url) throws SQLException {
public static void main(String[] args) {
// randomly pick one of the two endpoints to connect to,
// fail over to the other when there's connection issue
String url = System.getProperty("chUrl",
"jdbc:ch://(https://[email protected]:443),"
+ "(https://demo:[email protected])"
+ "/default?failover=1&load_balancing_policy=random");
String url = System.getProperty("chUrl", "jdbc:ch://localhost");

try {
System.out.println(exteralTables(url));
System.out.println(namedParameter(url));
System.out.println(renameResponseColumn(url));
System.out.println(unwrapToUseClientApi(url));

// requires ClickHouse 22.6+ with transaction enabled
System.out.println(manualTransaction(url));
} catch (SQLException e) {
e.printStackTrace();
}
Expand Down
Loading

0 comments on commit fdcac72

Please sign in to comment.