├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── v2-feedback.md ├── pull_request_template.md └── workflows │ ├── analysis.yml │ ├── benchmarks.yml │ ├── build.yml │ ├── nightly.yml │ ├── release.yml │ ├── run_examples.yml │ ├── stale.yml │ └── third_party_libs.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── clickhouse-benchmark ├── docs │ └── results │ │ ├── pull-request_418.json │ │ ├── v0.2.4.json │ │ ├── v0.2.5.json │ │ └── v0.2.6.json ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── clickhouse │ └── benchmark │ ├── BaseState.java │ ├── Constants.java │ ├── ServerState.java │ ├── client │ ├── ClientBenchmark.java │ ├── ClientState.java │ ├── Load.java │ └── Simple.java │ ├── jdbc │ ├── Basic.java │ ├── ConsumeValueFunction.java │ ├── DriverBenchmark.java │ ├── DriverState.java │ ├── Insertion.java │ ├── JdbcDriver.java │ ├── Query.java │ └── SupplyValueFunction.java │ └── misc │ ├── CompareBenchmark.java │ ├── FactoryBenchmark.java │ ├── QueueBenchmark.java │ ├── StreamBenchmark.java │ └── ValuesBenchmark.java ├── clickhouse-client ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── client │ │ │ ├── AbstractClient.java │ │ │ ├── AbstractSocketClient.java │ │ │ ├── ClickHouseClient.java │ │ │ ├── ClickHouseClientBuilder.java │ │ │ ├── ClickHouseCluster.java │ │ │ ├── ClickHouseConfig.java │ │ │ ├── ClickHouseCredentials.java │ │ │ ├── ClickHouseDnsResolver.java │ │ │ ├── ClickHouseException.java │ │ │ ├── ClickHouseLoadBalancingPolicy.java │ │ │ ├── ClickHouseNode.java │ │ │ ├── ClickHouseNodeManager.java │ │ │ ├── ClickHouseNodeSelector.java │ │ │ ├── ClickHouseNodes.java │ │ │ ├── ClickHouseParameterizedQuery.java │ │ │ ├── ClickHouseProtocol.java │ │ │ ├── ClickHouseRequest.java │ │ │ ├── ClickHouseRequestManager.java │ │ │ ├── ClickHouseResponse.java │ │ │ ├── ClickHouseResponseSummary.java │ │ │ ├── ClickHouseSimpleResponse.java │ │ │ ├── ClickHouseSocketFactory.java │ │ │ ├── ClickHouseSslContextProvider.java │ │ │ ├── ClickHouseStreamResponse.java │ │ │ ├── ClickHouseTransaction.java │ │ │ ├── ClickHouseTransactionException.java │ │ │ ├── ClickHouseVersionUtils.java │ │ │ ├── UnsupportedProtocolException.java │ │ │ ├── config │ │ │ ├── ClickHouseClientOption.java │ │ │ ├── ClickHouseDefaultSslContextProvider.java │ │ │ ├── ClickHouseDefaults.java │ │ │ ├── ClickHouseHealthCheckMethod.java │ │ │ ├── ClickHouseProxyType.java │ │ │ ├── ClickHouseSslMode.java │ │ │ └── package-info.java │ │ │ ├── naming │ │ │ └── SrvResolver.java │ │ │ └── package-info.java │ ├── java11 │ │ └── module-info.java │ ├── java9 │ │ └── module-info.java │ └── resources │ │ ├── META-INF │ │ ├── native-image │ │ │ └── com.clickhouse │ │ │ │ └── clickhouse-client │ │ │ │ ├── native-image.properties │ │ │ │ └── resource-config.json │ │ └── services │ │ │ └── com.clickhouse.client.ClickHouseSslContextProvider │ │ └── clickhouse-client-version.properties │ └── test │ ├── java │ └── com │ │ └── clickhouse │ │ └── client │ │ ├── AbstractClientTest.java │ │ ├── AbstractSocketClientTest.java │ │ ├── BaseIntegrationTest.java │ │ ├── ClickHouseClientBuilderTest.java │ │ ├── ClickHouseClientTest.java │ │ ├── ClickHouseClusterTest.java │ │ ├── ClickHouseConfigTest.java │ │ ├── ClickHouseExceptionTest.java │ │ ├── ClickHouseLoadBalancingPolicyTest.java │ │ ├── ClickHouseNodeSelectorTest.java │ │ ├── ClickHouseNodeTest.java │ │ ├── ClickHouseNodesTest.java │ │ ├── ClickHouseParameterizedQueryTest.java │ │ ├── ClickHouseProtocolTest.java │ │ ├── ClickHouseRequestTest.java │ │ ├── ClickHouseResponseSummaryTest.java │ │ ├── ClickHouseServerForTest.java │ │ ├── ClickHouseSimpleResponseTest.java │ │ ├── ClickHouseSslContextProviderTest.java │ │ ├── ClickHouseTestClient.java │ │ ├── ClientIntegrationTest.java │ │ ├── config │ │ └── ClickHouseDefaultSslContextProviderTest.java │ │ └── naming │ │ └── SrvResolverTest.java │ └── resources │ ├── META-INF │ └── services │ │ └── com.clickhouse.client.ClickHouseClient │ ├── README.md │ ├── client.crt │ ├── client.key │ ├── containers │ └── clickhouse-server │ │ ├── certs │ │ ├── KeyStore.jks │ │ ├── localhost.crt │ │ ├── localhost.csr │ │ ├── localhost.key │ │ ├── marsnet_ca.crt │ │ └── marsnet_ca.key │ │ ├── config.d │ │ └── custom_config.xml │ │ ├── patch │ │ └── users.d │ │ └── users.xml │ ├── empty.csv │ ├── pkey4test.pem │ ├── simplelogger.properties │ ├── some_user.crt │ ├── some_user.csr │ └── some_user.key ├── clickhouse-data ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ ├── config │ │ │ ├── ClickHouseBufferingMode.java │ │ │ ├── ClickHouseConfigChangeListener.java │ │ │ ├── ClickHouseDefaultOption.java │ │ │ ├── ClickHouseOption.java │ │ │ ├── ClickHouseRenameMethod.java │ │ │ └── package-info.java │ │ │ ├── data │ │ │ ├── ByteUtils.java │ │ │ ├── ClickHouseAggregateFunction.java │ │ │ ├── ClickHouseArraySequence.java │ │ │ ├── ClickHouseByteBuffer.java │ │ │ ├── ClickHouseByteUtils.java │ │ │ ├── ClickHouseCache.java │ │ │ ├── ClickHouseChecker.java │ │ │ ├── ClickHouseCityHash.java │ │ │ ├── ClickHouseColumn.java │ │ │ ├── ClickHouseCompression.java │ │ │ ├── ClickHouseCompressionAlgorithm.java │ │ │ ├── ClickHouseDataConfig.java │ │ │ ├── ClickHouseDataProcessor.java │ │ │ ├── ClickHouseDataStreamFactory.java │ │ │ ├── ClickHouseDataType.java │ │ │ ├── ClickHouseDataUpdater.java │ │ │ ├── ClickHouseDeferredValue.java │ │ │ ├── ClickHouseDeserializer.java │ │ │ ├── ClickHouseEnum.java │ │ │ ├── ClickHouseExternalTable.java │ │ │ ├── ClickHouseFile.java │ │ │ ├── ClickHouseFormat.java │ │ │ ├── ClickHouseFreezableMap.java │ │ │ ├── ClickHouseInputStream.java │ │ │ ├── ClickHouseOutputStream.java │ │ │ ├── ClickHousePassThruStream.java │ │ │ ├── ClickHousePipedOutputStream.java │ │ │ ├── ClickHouseRecord.java │ │ │ ├── ClickHouseRecordMapper.java │ │ │ ├── ClickHouseRecordTransformer.java │ │ │ ├── ClickHouseSerializer.java │ │ │ ├── ClickHouseSimpleRecord.java │ │ │ ├── ClickHouseStreamConfig.java │ │ │ ├── ClickHouseThreadFactory.java │ │ │ ├── ClickHouseUtils.java │ │ │ ├── ClickHouseValue.java │ │ │ ├── ClickHouseValues.java │ │ │ ├── ClickHouseVersion.java │ │ │ ├── ClickHouseWriter.java │ │ │ ├── DelegatedInputStream.java │ │ │ ├── UnloadableClassLoader.java │ │ │ ├── cache │ │ │ │ ├── CaffeineCache.java │ │ │ │ └── JdkLruCache.java │ │ │ ├── compress │ │ │ │ ├── BrotliSupport.java │ │ │ │ ├── Bz2Support.java │ │ │ │ ├── DeflateSupport.java │ │ │ │ ├── GzipSupport.java │ │ │ │ ├── Lz4Support.java │ │ │ │ ├── NoneSupport.java │ │ │ │ ├── SnappySupport.java │ │ │ │ ├── XzSupport.java │ │ │ │ └── ZstdSupport.java │ │ │ ├── format │ │ │ │ ├── BinaryDataProcessor.java │ │ │ │ ├── BinaryStreamUtils.java │ │ │ │ ├── ClickHouseBinaryFormatProcessor.java │ │ │ │ ├── ClickHouseRowBinaryProcessor.java │ │ │ │ ├── ClickHouseTabSeparatedProcessor.java │ │ │ │ ├── JsonStreamUtils.java │ │ │ │ ├── TextDataProcessor.java │ │ │ │ └── tsv │ │ │ │ │ ├── ArrayByteFragment.java │ │ │ │ │ ├── ByteFragment.java │ │ │ │ │ ├── FastByteArrayInputStream.java │ │ │ │ │ ├── FastByteArrayOutputStream.java │ │ │ │ │ ├── StreamSplitter.java │ │ │ │ │ └── package-info.java │ │ │ ├── mapper │ │ │ │ ├── AbstractRecordMapper.java │ │ │ │ ├── CompiledRecordMapper.java │ │ │ │ ├── CustomRecordMappers.java │ │ │ │ ├── DynamicRecordMapper.java │ │ │ │ ├── IterableRecordWrapper.java │ │ │ │ ├── RecordMapperFactory.java │ │ │ │ └── WrappedMapper.java │ │ │ ├── stream │ │ │ │ ├── AbstractByteArrayInputStream.java │ │ │ │ ├── AbstractByteArrayOutputStream.java │ │ │ │ ├── AbstractByteBufferInputStream.java │ │ │ │ ├── AdaptiveQueue.java │ │ │ │ ├── BlockingInputStream.java │ │ │ │ ├── BlockingPipedOutputStream.java │ │ │ │ ├── ByteArrayQueueInputStream.java │ │ │ │ ├── CapacityPolicy.java │ │ │ │ ├── DeferredInputStream.java │ │ │ │ ├── DeferredOutputStream.java │ │ │ │ ├── EmptyInputStream.java │ │ │ │ ├── EmptyOutputStream.java │ │ │ │ ├── IterableByteArrayInputStream.java │ │ │ │ ├── IterableByteBufferInputStream.java │ │ │ │ ├── IterableMultipleInputStream.java │ │ │ │ ├── IterableObjectInputStream.java │ │ │ │ ├── Lz4InputStream.java │ │ │ │ ├── Lz4OutputStream.java │ │ │ │ ├── NonBlockingInputStream.java │ │ │ │ ├── NonBlockingPipedOutputStream.java │ │ │ │ ├── RestrictedInputStream.java │ │ │ │ ├── WrappedInputStream.java │ │ │ │ └── WrappedOutputStream.java │ │ │ └── value │ │ │ │ ├── ClickHouseArrayValue.java │ │ │ │ ├── ClickHouseBigDecimalValue.java │ │ │ │ ├── ClickHouseBigIntegerValue.java │ │ │ │ ├── ClickHouseBitmap.java │ │ │ │ ├── ClickHouseBitmapValue.java │ │ │ │ ├── ClickHouseBoolValue.java │ │ │ │ ├── ClickHouseByteValue.java │ │ │ │ ├── ClickHouseDateTimeValue.java │ │ │ │ ├── ClickHouseDateValue.java │ │ │ │ ├── ClickHouseDoubleValue.java │ │ │ │ ├── ClickHouseEmptyValue.java │ │ │ │ ├── ClickHouseEnumValue.java │ │ │ │ ├── ClickHouseFloatValue.java │ │ │ │ ├── ClickHouseGeoMultiPolygonValue.java │ │ │ │ ├── ClickHouseGeoPointValue.java │ │ │ │ ├── ClickHouseGeoPolygonValue.java │ │ │ │ ├── ClickHouseGeoRingValue.java │ │ │ │ ├── ClickHouseInstantValue.java │ │ │ │ ├── ClickHouseIntegerValue.java │ │ │ │ ├── ClickHouseIpv4Value.java │ │ │ │ ├── ClickHouseIpv6Value.java │ │ │ │ ├── ClickHouseLongValue.java │ │ │ │ ├── ClickHouseMapValue.java │ │ │ │ ├── ClickHouseNestedValue.java │ │ │ │ ├── ClickHouseObjectValue.java │ │ │ │ ├── ClickHouseOffsetDateTimeValue.java │ │ │ │ ├── ClickHouseShortValue.java │ │ │ │ ├── ClickHouseStringValue.java │ │ │ │ ├── ClickHouseTupleValue.java │ │ │ │ ├── ClickHouseUuidValue.java │ │ │ │ ├── UnsignedByte.java │ │ │ │ ├── UnsignedInteger.java │ │ │ │ ├── UnsignedLong.java │ │ │ │ ├── UnsignedShort.java │ │ │ │ ├── array │ │ │ │ ├── ClickHouseBoolArrayValue.java │ │ │ │ ├── ClickHouseByteArrayValue.java │ │ │ │ ├── ClickHouseDoubleArrayValue.java │ │ │ │ ├── ClickHouseFloatArrayValue.java │ │ │ │ ├── ClickHouseIntArrayValue.java │ │ │ │ ├── ClickHouseLongArrayValue.java │ │ │ │ └── ClickHouseShortArrayValue.java │ │ │ │ └── package-info.java │ │ │ └── logging │ │ │ ├── JdkLogger.java │ │ │ ├── JdkLoggerFactory.java │ │ │ ├── LogMessage.java │ │ │ ├── Logger.java │ │ │ ├── LoggerFactory.java │ │ │ ├── Slf4jLogger.java │ │ │ ├── Slf4jLoggerFactory.java │ │ │ └── package-info.java │ ├── java11 │ │ ├── com │ │ │ └── clickhouse │ │ │ │ └── data │ │ │ │ └── ByteUtils.java │ │ └── module-info.java │ ├── java9 │ │ ├── com │ │ │ └── clickhouse │ │ │ │ └── data │ │ │ │ └── ByteUtils.java │ │ └── module-info.java │ └── resources │ │ └── META-INF │ │ └── native-image │ │ └── com.clickhouse │ │ └── clickhouse-data │ │ └── native-image.properties │ └── test │ ├── java │ └── com │ │ └── clickhouse │ │ ├── config │ │ ├── ClickHouseOptionTest.java │ │ └── ClickHouseRenameMethodTest.java │ │ ├── data │ │ ├── BaseClickHouseValueTest.java │ │ ├── ClickHouseByteBufferTest.java │ │ ├── ClickHouseByteUtilsTest.java │ │ ├── ClickHouseCheckerTest.java │ │ ├── ClickHouseColumnTest.java │ │ ├── ClickHouseCompressionAlgorithmTest.java │ │ ├── ClickHouseDataConfigTest.java │ │ ├── ClickHouseDataStreamFactoryTest.java │ │ ├── ClickHouseDataTypeTest.java │ │ ├── ClickHouseDeferredValueTest.java │ │ ├── ClickHouseFileTest.java │ │ ├── ClickHouseFreezableMapTest.java │ │ ├── ClickHouseInputStreamTest.java │ │ ├── ClickHouseOutputStreamTest.java │ │ ├── ClickHousePassThruStreamTest.java │ │ ├── ClickHouseSimpleRecordTest.java │ │ ├── ClickHouseTestDataConfig.java │ │ ├── ClickHouseUtilsTest.java │ │ ├── ClickHouseValuesTest.java │ │ ├── ClickHouseVersionTest.java │ │ ├── DelegatedInputStreamTest.java │ │ ├── TestServiceImplementation.java │ │ ├── TestServiceInterface.java │ │ ├── UnloadableClassLoaderTest.java │ │ ├── cache │ │ │ ├── CaffeineCacheTest.java │ │ │ └── JdkLruCacheTest.java │ │ ├── format │ │ │ ├── BinaryStreamUtilsTest.java │ │ │ ├── ClickHouseRowBinaryProcessorTest.java │ │ │ ├── ClickHouseTabSeparatedProcessorTest.java │ │ │ └── JsonStreamUtilsTest.java │ │ ├── mapper │ │ │ ├── CustomRecordMappersTest.java │ │ │ ├── DynamicRecordMapperTest.java │ │ │ └── RecordMapperFactoryTest.java │ │ ├── stream │ │ │ ├── BlockingPipedOutputStreamTest.java │ │ │ ├── InputStreamImplTest.java │ │ │ ├── IterableByteArrayInputStreamTests.java │ │ │ ├── Lz4InputStreamTest.java │ │ │ ├── Lz4OutputStreamTest.java │ │ │ ├── NonBlockingPipedOutputStreamTest.java │ │ │ └── OutputStreamImplTest.java │ │ └── value │ │ │ ├── BaseDataProcessorTest.java │ │ │ ├── ClickHouseBitmapTest.java │ │ │ ├── ClickHouseBoolValueTest.java │ │ │ ├── ClickHouseByteValueTest.java │ │ │ ├── ClickHouseDateTimeValueTest.java │ │ │ ├── ClickHouseDateValueTest.java │ │ │ ├── ClickHouseDoubleValueTest.java │ │ │ ├── ClickHouseEnumValueTest.java │ │ │ ├── ClickHouseFloatValueTest.java │ │ │ ├── ClickHouseGeoPointValueTest.java │ │ │ ├── ClickHouseIntegerValueTest.java │ │ │ ├── ClickHouseLongValueTest.java │ │ │ ├── ClickHouseNestedValueTest.java │ │ │ ├── ClickHouseOffsetDateTimeValueTest.java │ │ │ ├── ClickHouseShortValueTest.java │ │ │ ├── ClickHouseStringValueTest.java │ │ │ ├── ClickHouseTupleValueTest.java │ │ │ ├── UnsignedByteTest.java │ │ │ ├── UnsignedIntegerTest.java │ │ │ ├── UnsignedLongTest.java │ │ │ ├── UnsignedShortTest.java │ │ │ ├── WriterFunction.java │ │ │ └── array │ │ │ ├── ClickHouseByteArrayValueTest.java │ │ │ └── ClickHouseLongArrayValueTest.java │ │ └── logging │ │ ├── JdkLoggerTest.java │ │ ├── LogMessageTest.java │ │ ├── LoggerTest.java │ │ └── Slf4jLoggerTest.java │ └── resources │ ├── META-INF │ └── services │ │ └── com.clickhouse.data.TestServiceInterface │ └── simplelogger.properties ├── clickhouse-http-client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── client │ │ │ └── http │ │ │ ├── ApacheHttpConnectionImpl.java │ │ │ ├── ClickHouseHttpClient.java │ │ │ ├── ClickHouseHttpConnection.java │ │ │ ├── ClickHouseHttpConnectionFactory.java │ │ │ ├── ClickHouseHttpEntity.java │ │ │ ├── ClickHouseHttpProto.java │ │ │ ├── ClickHouseHttpResponse.java │ │ │ ├── HttpUrlConnectionImpl.java │ │ │ └── config │ │ │ ├── ClickHouseHttpOption.java │ │ │ └── HttpConnectionProvider.java │ ├── java11 │ │ ├── com │ │ │ └── clickhouse │ │ │ │ └── client │ │ │ │ └── http │ │ │ │ ├── ClickHouseHttpConnectionFactory.java │ │ │ │ ├── ClickHouseResponseHandler.java │ │ │ │ └── HttpClientConnectionImpl.java │ │ └── module-info.java │ ├── java9 │ │ └── module-info.java │ └── resources │ │ └── META-INF │ │ ├── native-image │ │ └── com.clickhouse │ │ │ └── clickhouse-http-client │ │ │ └── native-image.properties │ │ └── services │ │ └── com.clickhouse.client.ClickHouseClient │ └── test │ ├── java │ └── com │ │ └── clickhouse │ │ └── client │ │ └── http │ │ ├── ApacheHttpConnectionImplTest.java │ │ ├── ClickHouseHttpClientTest.java │ │ ├── ClickHouseHttpConnectionTest.java │ │ └── DefaultHttpConnectionTest.java │ └── resources │ └── simplelogger.properties ├── clickhouse-jdbc ├── README.md ├── docs │ └── datetime.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── jdbc │ │ │ ├── AbstractResultSet.java │ │ │ ├── ClickHouseArray.java │ │ │ ├── ClickHouseBlob.java │ │ │ ├── ClickHouseClob.java │ │ │ ├── ClickHouseConnection.java │ │ │ ├── ClickHouseDataSource.java │ │ │ ├── ClickHouseDatabaseMetaData.java │ │ │ ├── ClickHouseDriver.java │ │ │ ├── ClickHousePreparedStatement.java │ │ │ ├── ClickHouseResultSet.java │ │ │ ├── ClickHouseResultSetMetaData.java │ │ │ ├── ClickHouseScrollableResultSet.java │ │ │ ├── ClickHouseStatement.java │ │ │ ├── ClickHouseStruct.java │ │ │ ├── ClickHouseXml.java │ │ │ ├── CombinedResultSet.java │ │ │ ├── DataSourceV1.java │ │ │ ├── DriverV1.java │ │ │ ├── JdbcConfig.java │ │ │ ├── JdbcParameterizedQuery.java │ │ │ ├── JdbcParseHandler.java │ │ │ ├── JdbcTypeMapping.java │ │ │ ├── JdbcWrapper.java │ │ │ ├── Main.java │ │ │ ├── SqlExceptionUtils.java │ │ │ ├── internal │ │ │ ├── AbstractPreparedStatement.java │ │ │ ├── ClickHouseConnectionImpl.java │ │ │ ├── ClickHouseJdbcUrlParser.java │ │ │ ├── ClickHouseParameterMetaData.java │ │ │ ├── ClickHouseStatementImpl.java │ │ │ ├── InputBasedPreparedStatement.java │ │ │ ├── JdbcSavepoint.java │ │ │ ├── JdbcTransaction.java │ │ │ ├── SqlBasedPreparedStatement.java │ │ │ ├── StreamBasedPreparedStatement.java │ │ │ └── TableBasedPreparedStatement.java │ │ │ └── parser │ │ │ ├── ClickHouseSqlStatement.java │ │ │ ├── ClickHouseSqlUtils.java │ │ │ ├── LanguageType.java │ │ │ ├── OperationType.java │ │ │ ├── ParseHandler.java │ │ │ └── StatementType.java │ ├── java11 │ │ └── module-info.java │ ├── java9 │ │ └── module-info.java │ ├── javacc │ │ └── ClickHouseSqlParser.jj │ └── resources │ │ ├── META-INF │ │ ├── native-image │ │ │ └── com.clickhouse │ │ │ │ └── clickhouse-jdbc │ │ │ │ ├── native-image.properties │ │ │ │ └── reflect-config.json │ │ └── services │ │ │ └── java.sql.Driver │ │ └── clickhouse-jdbc-version.properties │ └── test │ ├── java │ └── com │ │ └── clickhouse │ │ └── jdbc │ │ ├── AccessManagementTest.java │ │ ├── ClickHouseConnectionTest.java │ │ ├── ClickHouseDataSourceTest.java │ │ ├── ClickHouseDatabaseMetaDataTest.java │ │ ├── ClickHouseDriverTest.java │ │ ├── ClickHousePreparedStatementTest.java │ │ ├── ClickHouseResultSetTest.java │ │ ├── ClickHouseStatementTest.java │ │ ├── CombinedResultSetTest.java │ │ ├── GenericJDBCTest.java │ │ ├── JdbcIntegrationTest.java │ │ ├── JdbcIssuesTest.java │ │ ├── JdbcParameterizedQueryTest.java │ │ ├── JdbcParseHandlerTest.java │ │ ├── comparison │ │ └── DateTimeComparisonTest.java │ │ ├── internal │ │ ├── ClickHouseConnectionImplTest.java │ │ ├── ClickHouseJdbcUrlParserTest.java │ │ └── JdbcTransactionTest.java │ │ └── parser │ │ ├── ClickHouseSqlParserTest.java │ │ └── ClickHouseSqlUtilsTest.java │ ├── perf │ ├── README.md │ └── com │ │ └── clickhouse │ │ └── jdbc │ │ └── perf │ │ ├── JDBCBenchmarkBase.java │ │ ├── JDBCBenchmarkRunner.java │ │ ├── JDBCInsertBenchmark.java │ │ └── JDBCSelectBenchmark.java │ └── resources │ ├── data_samples │ ├── test_sample.orc.gz │ └── test_sample.parquet.gz │ ├── simplelogger.properties │ └── sqls │ ├── issue-441_with-totals.sql │ ├── issue-555_custom-format.sql │ └── with-clause.sql ├── clickhouse-r2dbc ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── r2dbc │ │ │ ├── ClickHouseBatch.java │ │ │ ├── ClickHouseColumnMetadata.java │ │ │ ├── ClickHousePair.java │ │ │ ├── ClickHouseResult.java │ │ │ ├── ClickHouseResult091.java │ │ │ ├── ClickHouseRow.java │ │ │ ├── ClickHouseRowMetadata.java │ │ │ ├── ClickHouseStatement.java │ │ │ ├── ClickHouseStatementBinding.java │ │ │ ├── connection │ │ │ ├── ClickHouseConnection.java │ │ │ ├── ClickHouseConnectionFactory.java │ │ │ ├── ClickHouseConnectionFactoryMetadata.java │ │ │ ├── ClickHouseConnectionFactoryProvider.java │ │ │ └── ClickHouseConnectionMetadata.java │ │ │ └── types │ │ │ └── ClickHouseDataTypeWrapper.java │ ├── java11 │ │ └── module-info.java │ ├── java9 │ │ └── module-info.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── io.r2dbc.spi.ConnectionFactoryProvider │ └── test │ ├── java │ └── com │ │ └── clickhouse │ │ └── r2dbc │ │ ├── BaseR2dbcTest.java │ │ ├── connection │ │ └── ClickHouseConnectionTest.java │ │ └── spi │ │ └── test │ │ └── R2DBCTestKitImplTest.java │ └── resources │ └── simplelogger.properties ├── clickhouse-tcp-client └── pom.xml ├── client-v2 ├── docs │ └── dependencies.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── client │ │ │ └── api │ │ │ ├── Client.java │ │ │ ├── ClientConfigProperties.java │ │ │ ├── ClientException.java │ │ │ ├── ClientFaultCause.java │ │ │ ├── ClientMisconfigurationException.java │ │ │ ├── ConnectionInitiationException.java │ │ │ ├── ConnectionReuseStrategy.java │ │ │ ├── DataStreamWriter.java │ │ │ ├── DataTypeUtils.java │ │ │ ├── ServerException.java │ │ │ ├── command │ │ │ ├── CommandResponse.java │ │ │ └── CommandSettings.java │ │ │ ├── data_formats │ │ │ ├── ClickHouseBinaryFormatReader.java │ │ │ ├── ClickHouseBinaryFormatWriter.java │ │ │ ├── NativeFormatReader.java │ │ │ ├── RowBinaryFormatReader.java │ │ │ ├── RowBinaryFormatSerializer.java │ │ │ ├── RowBinaryFormatWriter.java │ │ │ ├── RowBinaryWithNamesAndTypesFormatReader.java │ │ │ ├── RowBinaryWithNamesFormatReader.java │ │ │ └── internal │ │ │ │ ├── AbstractBinaryFormatReader.java │ │ │ │ ├── BinaryReaderBackedRecord.java │ │ │ │ ├── BinaryStreamReader.java │ │ │ │ ├── InetAddressConverter.java │ │ │ │ ├── MapBackedRecord.java │ │ │ │ ├── NumberConverter.java │ │ │ │ ├── ProcessParser.java │ │ │ │ └── SerializerUtils.java │ │ │ ├── enums │ │ │ ├── Protocol.java │ │ │ └── ProxyType.java │ │ │ ├── http │ │ │ └── ClickHouseHttpProto.java │ │ │ ├── insert │ │ │ ├── InsertResponse.java │ │ │ └── InsertSettings.java │ │ │ ├── internal │ │ │ ├── BasicObjectsPool.java │ │ │ ├── CachingObjectsSupplier.java │ │ │ ├── ClickHouseLZ4InputStream.java │ │ │ ├── ClickHouseLZ4OutputStream.java │ │ │ ├── ClientStatisticsHolder.java │ │ │ ├── EnvUtils.java │ │ │ ├── Gauge.java │ │ │ ├── HttpAPIClientHelper.java │ │ │ ├── LZ4Entity.java │ │ │ ├── MapUtils.java │ │ │ ├── ServerSettings.java │ │ │ ├── StopWatch.java │ │ │ ├── TableSchemaParser.java │ │ │ └── ValidationUtils.java │ │ │ ├── metadata │ │ │ ├── ColumnToMethodMatchingStrategy.java │ │ │ ├── DefaultColumnToMethodMatchingStrategy.java │ │ │ ├── NoSuchColumnException.java │ │ │ └── TableSchema.java │ │ │ ├── metrics │ │ │ ├── ClientMetrics.java │ │ │ ├── Metric.java │ │ │ ├── MicrometerLoader.java │ │ │ ├── OperationMetrics.java │ │ │ └── ServerMetrics.java │ │ │ ├── query │ │ │ ├── GenericRecord.java │ │ │ ├── NullValueException.java │ │ │ ├── QueryResponse.java │ │ │ ├── QuerySettings.java │ │ │ ├── QueryStatement.java │ │ │ └── Records.java │ │ │ ├── serde │ │ │ ├── DataSerializationException.java │ │ │ ├── POJOFieldDeserializer.java │ │ │ ├── POJOFieldSerializer.java │ │ │ ├── POJOSerDe.java │ │ │ └── SerializerNotFoundException.java │ │ │ └── transport │ │ │ ├── Endpoint.java │ │ │ └── HttpEndpoint.java │ └── resources │ │ └── client-v2-version.properties │ └── test │ └── java │ └── com │ └── clickhouse │ └── client │ ├── ClientTests.java │ ├── HttpTransportTests.java │ ├── ProxyTests.java │ ├── SettingsTests.java │ ├── api │ ├── DataTypeUtilsTests.java │ ├── data_formats │ │ ├── ClickHouseBinaryFormatReaderTest.java │ │ └── internal │ │ │ ├── BinaryStreamReaderTests.java │ │ │ └── SerializerUtilsTests.java │ └── internal │ │ └── HttpAPIClientHelperTest.java │ ├── command │ └── CommandTests.java │ ├── datatypes │ ├── DataTypeTests.java │ ├── DataTypesTestingPOJO.java │ ├── NestedTypesDTO.java │ ├── RowBinaryFormatWriterTest.java │ └── VariantDTO.java │ ├── insert │ ├── InsertClientContentCompressionTests.java │ ├── InsertClientHttpCompressionTests.java │ ├── InsertTests.java │ ├── NoSettersPOJO.java │ ├── PojoWithDynamic.java │ ├── PojoWithJSON.java │ ├── SamplePOJO.java │ └── SimplePOJO.java │ ├── internal │ ├── SamplePOJOForSerialization.java │ ├── SerializerUtilsTests.java │ └── SmallTests.java │ ├── metadata │ └── MetadataTests.java │ ├── metrics │ └── MetricsTest.java │ └── query │ ├── AggregateFuncDTO.java │ ├── BinaryReadyReusesBuffersTests.java │ ├── NoGettersPOJO.java │ ├── QuerySamplePOJO.java │ ├── QueryServerContentCompressionTests.java │ ├── QueryServerHttpCompressionTests.java │ ├── QueryTests.java │ └── SimplePOJO.java ├── examples ├── client-v2 │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── examples │ │ │ └── client_v2 │ │ │ ├── BigDatasetExamples.java │ │ │ ├── ExperimentalJSONExample.java │ │ │ ├── Main.java │ │ │ ├── POJO2DbWriter.java │ │ │ ├── SimpleReader.java │ │ │ ├── Stream2DbWriter.java │ │ │ ├── TextFormatsReader.java │ │ │ └── data │ │ │ ├── ArticleViewEvent.java │ │ │ ├── NumbersRecord.java │ │ │ └── PojoWithJSON.java │ │ └── resources │ │ ├── article_view_event_init.sql │ │ ├── sample_hacker_news_posts.json │ │ └── simple_writer_init.sql ├── client │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── clickhouse │ │ │ └── examples │ │ │ ├── formats │ │ │ └── ProtobufMain.java │ │ │ ├── jdbc │ │ │ └── Main.java │ │ │ └── protos │ │ │ ├── UIEvent.java │ │ │ ├── UIEventOrBuilder.java │ │ │ └── UIStatsEventProtos.java │ │ └── proto │ │ └── ui_stats_event.proto ├── demo-kotlin-service │ ├── .gitignore │ ├── build.gradle.kts │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ └── src │ │ └── main │ │ ├── kotlin │ │ └── com │ │ │ └── clickhouse │ │ │ └── examples │ │ │ └── service │ │ │ ├── Application.kt │ │ │ ├── Database.kt │ │ │ └── Routing.kt │ │ └── resources │ │ ├── application.yaml │ │ └── logback.xml ├── demo-service │ ├── .gitignore │ ├── README.md │ ├── build.gradle.kts │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── clickhouse │ │ │ │ └── demo_service │ │ │ │ ├── BasicObjectsPool.java │ │ │ │ ├── CalculationResult.java │ │ │ │ ├── DbConfiguration.java │ │ │ │ ├── DemoServiceApplication.java │ │ │ │ ├── JPAInsertController.java │ │ │ │ ├── MetricsConfig.java │ │ │ │ ├── ObjectsPreparedCollection.java │ │ │ │ ├── QueryController.java │ │ │ │ ├── data │ │ │ │ ├── UIEvent.java │ │ │ │ └── VirtualDatasetRecord.java │ │ │ │ └── jpa │ │ │ │ ├── ClickHouseStringArrayType.java │ │ │ │ └── UIEventsDbRepository.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── clickhouse │ │ └── .keep ├── jdbc │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── clickhouse │ │ └── examples │ │ └── jdbc │ │ └── Basic.java └── r2dbc │ ├── README.md │ ├── clickhouse-r2dbc-spring-webflux-sample │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── r2dbc │ │ │ └── spring │ │ │ └── webflux │ │ │ └── sample │ │ │ ├── Application.java │ │ │ ├── config │ │ │ └── R2DBCConfig.java │ │ │ ├── controller │ │ │ └── ClickController.java │ │ │ ├── model │ │ │ ├── Click.java │ │ │ └── ClickStats.java │ │ │ └── repository │ │ │ └── ClickRepository.java │ │ └── resources │ │ ├── application.yaml │ │ ├── init.sql │ │ ├── log4j.properties │ │ └── postman │ │ └── clickhouse-r2dbc-sample.postman_collection.json │ ├── misc │ └── docker │ │ ├── clickhouse-docker-mount │ │ ├── config.d │ │ │ └── docker_related_config.xml │ │ ├── config.xml │ │ ├── docker_related_config.xml │ │ └── users.xml │ │ └── compose.yaml │ └── pom.xml ├── jdbc-v2 ├── README.md ├── pom.xml └── src │ ├── main │ ├── antlr4 │ │ └── com │ │ │ └── clickhouse │ │ │ └── jdbc │ │ │ └── internal │ │ │ ├── ClickHouseLexer.g4 │ │ │ └── ClickHouseParser.g4 │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ ├── data │ │ │ └── Tuple.java │ │ │ └── jdbc │ │ │ ├── ConnectionImpl.java │ │ │ ├── DataSourceImpl.java │ │ │ ├── Driver.java │ │ │ ├── JdbcV2Wrapper.java │ │ │ ├── PreparedStatementImpl.java │ │ │ ├── ResultSetImpl.java │ │ │ ├── StatementImpl.java │ │ │ ├── WriterStatementImpl.java │ │ │ ├── internal │ │ │ ├── ClientInfoProperties.java │ │ │ ├── DriverProperties.java │ │ │ ├── ExceptionUtils.java │ │ │ ├── JdbcConfiguration.java │ │ │ ├── JdbcUtils.java │ │ │ ├── MetadataResultSet.java │ │ │ ├── ParsedPreparedStatement.java │ │ │ ├── ParsedStatement.java │ │ │ └── SqlParser.java │ │ │ ├── metadata │ │ │ ├── DatabaseMetaDataImpl.java │ │ │ ├── ParameterMetaDataImpl.java │ │ │ └── ResultSetMetaDataImpl.java │ │ │ └── types │ │ │ └── Array.java │ ├── java11 │ │ └── module-info.java │ ├── javacc │ │ └── ClickHouseSqlParser.jj │ └── resources │ │ ├── META-INF │ │ ├── native-image │ │ │ └── com.clickhouse │ │ │ │ └── clickhouse-jdbc │ │ │ │ ├── native-image.properties │ │ │ │ └── reflect-config.json │ │ └── services │ │ │ └── java.sql.Driver │ │ └── jdbc-v2-version.properties │ └── test │ ├── java │ └── com │ │ └── clickhouse │ │ └── jdbc │ │ ├── ConnectionTest.java │ │ ├── DataSourceTest.java │ │ ├── DataTypeTests.java │ │ ├── DriverTest.java │ │ ├── JdbcIntegrationTest.java │ │ ├── PreparedStatementTest.java │ │ ├── ResultSetImplTest.java │ │ ├── StatementTest.java │ │ ├── internal │ │ ├── JdbcConfigurationTest.java │ │ ├── JdbcUtilsTest.java │ │ └── SqlParserTest.java │ │ └── metadata │ │ ├── DatabaseMetaDataTest.java │ │ ├── ParameterMetaDataImplTest.java │ │ └── ResultSetMetaDataImplTest.java │ └── resources │ └── simplelogger.properties ├── performance ├── README.md ├── pom.xml ├── sample_dataset.sql └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── clickhouse │ │ │ └── benchmark │ │ │ ├── BenchmarkRunner.java │ │ │ ├── TestEnvironment.java │ │ │ ├── clients │ │ │ ├── BenchmarkBase.java │ │ │ ├── Compression.java │ │ │ ├── ConcurrentInsertClient.java │ │ │ ├── ConcurrentQueryClient.java │ │ │ ├── DataTypes.java │ │ │ ├── Deserializers.java │ │ │ ├── InsertClient.java │ │ │ ├── JDBCInsert.java │ │ │ ├── JDBCQuery.java │ │ │ ├── MixedWorkload.java │ │ │ ├── QueryClient.java │ │ │ └── Serializers.java │ │ │ └── data │ │ │ ├── ClickHouseDataTypesShort.java │ │ │ ├── DataSet.java │ │ │ ├── DataSetGenerator.java │ │ │ ├── DataSets.java │ │ │ ├── FileDataSet.java │ │ │ ├── SimpleDataSet.java │ │ │ └── SyntheticDataSet.java │ └── resources │ │ └── simplelogger.properties │ └── test │ └── com │ └── clickhouse │ └── benchmark │ └── BenchmarkRunner.java ├── pom.xml ├── release.sh └── third-party-libraries ├── README.md ├── io.grpc ├── pom.xml └── src │ └── main │ └── java │ ├── io │ └── grpc │ │ ├── LoadBalancerProvider.java │ │ ├── ManagedChannelProvider.java │ │ ├── NameResolverProvider.java │ │ ├── ServerProvider.java │ │ └── netty │ │ └── shaded │ │ └── io │ │ ├── grpc │ │ └── netty │ │ │ └── DummyClass.java │ │ └── netty │ │ ├── channel │ │ └── DummyClass.java │ │ └── handler │ │ ├── DummyClass.java │ │ ├── codec │ │ ├── DummyClass.java │ │ └── http2 │ │ │ └── DummyClass.java │ │ └── ssl │ │ ├── DummyClass.java │ │ └── util │ │ └── DummyClass.java │ └── module-info.java ├── org.apache.commons.compress ├── pom.xml └── src │ └── main │ └── java │ ├── module-info.java │ └── org │ └── apache │ └── commons │ └── compress │ ├── DummyClass.java │ └── compressors │ ├── DummyClass.java │ ├── bzip2 │ └── DummyClass.java │ ├── deflate │ └── DummyClass.java │ ├── gzip │ └── DummyClass.java │ ├── lz4 │ └── DummyClass.java │ └── snappy │ └── DummyClass.java ├── org.congocc ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── congocc │ └── DummyClass.java ├── org.roaringbitmap ├── pom.xml └── src │ └── main │ └── java │ ├── module-info.java │ └── org │ └── roaringbitmap │ ├── DummyClass.java │ ├── buffer │ └── DummyClass.java │ └── longlong │ └── DummyClass.java └── pom.xml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report an bug 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 12 | ## Description 13 | 14 | ### Steps to reproduce 15 | 1. 16 | 2. 17 | 3. 18 | ### Error Log or Exception StackTrace 19 | 20 | ``` 21 | ``` 22 | 23 | 24 | ### Expected Behaviour 25 | 26 | ### Code Example 27 | 28 | ```java 29 | 30 | 31 | ``` 32 | 33 | ### Configuration 34 | 35 | #### Client Configuration 36 | ```java 37 | 38 | ``` 39 | 40 | #### Environment 41 | * [ ] Cloud 42 | * Client version: 43 | * Language version: 44 | * OS: 45 | 46 | #### ClickHouse Server 47 | * ClickHouse Server version: 48 | * ClickHouse Server non-default settings, if any: 49 | * `CREATE TABLE` statements for tables involved: 50 | * Sample data for all these tables, use [clickhouse-obfuscator](https://github.com/ClickHouse/ClickHouse/blob/master/programs/obfuscator/Obfuscator.cpp#L42-L80) if necessary 51 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for the package 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | ### Use case 12 | 13 | ### Describe the solution you'd like 14 | 15 | ### Describe the alternatives you've considered 16 | 17 | ### Additional context 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/v2-feedback.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: V2 Feedback 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: v2-feedback 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe your feedback 11 | 12 | ### Code example 13 | ```java 14 | ``` 15 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Summary 2 | 3 | 4 | Closes 5 | ## Checklist 6 | Delete items not relevant to your PR: 7 | - [ ] Closes # 8 | - [ ] Unit and integration tests covering the common scenarios were added 9 | - [ ] A human-readable description of the changes was provided to include in CHANGELOG 10 | - [ ] For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials 11 | -------------------------------------------------------------------------------- /.github/workflows/third_party_libs.yml: -------------------------------------------------------------------------------- 1 | name: ThirdPartyLibs 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version: 7 | description: "Release version" 8 | required: true 9 | default: "1.9.0" 10 | 11 | jobs: 12 | release: 13 | name: "Build and Publish Repackaged 3rd Party Libraries" 14 | runs-on: "ubuntu-latest" 15 | 16 | steps: 17 | - name: Check out Git repository 18 | uses: actions/checkout@v3 19 | - name: Install Java and Maven 20 | uses: actions/setup-java@v3 21 | with: 22 | distribution: "temurin" 23 | java-version: 11 24 | cache: 'maven' 25 | - name: Update pom files and reduce logs 26 | run: | 27 | find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ github.event.inputs.version }}|g' \ 28 | -e 's|^\( \).*\(\)$|\1${{ github.event.inputs.version }}\2|' \ 29 | -e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \; 30 | find . -type f -name "simplelogger.*" -exec rm -fv '{}' \; 31 | - name: Release Maven package 32 | uses: zhicwu/action-maven-publish@master 33 | with: 34 | directory: ./third-party-libraries/ 35 | maven_profiles: release 36 | gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} 37 | gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} 38 | nexus_username: ${{ secrets.SONATYPE_USER }} 39 | nexus_password: ${{ secrets.SONATYPE_PASSWD }} 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # MacOS 2 | .DS_Store 3 | 4 | # Java Files 5 | *.bgv 6 | *.class 7 | *.jar 8 | *.war 9 | *.ear 10 | *.out 11 | 12 | # VSCode 13 | .bloop 14 | .metals 15 | .vscode 16 | .factorypath 17 | 18 | # Eclipse 19 | .classpath 20 | .project 21 | .settings/ 22 | 23 | # Eclipse TestNG plugin 24 | test-output/ 25 | 26 | # Intellij 27 | .idea/ 28 | *.iml 29 | *.iws 30 | out/ 31 | 32 | # Maven 33 | .antlr/ 34 | log/ 35 | target/ 36 | 37 | # Generated files 38 | .flattened-pom.xml 39 | dependency-reduced-pom.xml 40 | **/parser/javacc/* 41 | **/parser/*CharStream.java 42 | **/parser/ClickHouseSqlParser.java 43 | **/parser/ClickHouseSqlParserConstants.java 44 | **/parser/ClickHouseSqlParserTokenManager.java 45 | **/parser/Token*.java 46 | **/parser/ParseException.java 47 | java.prof 48 | jmh-result.* 49 | profile.html 50 | jdbc-v2/gen 51 | 52 | # Shell scripts 53 | *.sh 54 | 55 | # test configuration 56 | **/test/resources/test.properties 57 | performance/jmh-simple-results.json 58 | *.csv 59 | *.sql 60 | *.json 61 | -------------------------------------------------------------------------------- /clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/Constants.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark; 2 | 3 | /** 4 | * Constant interface. 5 | */ 6 | public class Constants { 7 | public static final String DEFAULT_HOST = "127.0.0.1"; 8 | public static final String DEFAULT_DB = "system"; 9 | public static final String DEFAULT_USER = "default"; 10 | public static final String DEFAULT_PASSWD = ""; 11 | 12 | public static final int GRPC_PORT = 9100; 13 | public static final int HTTP_PORT = 8123; 14 | public static final int MYSQL_PORT = 9004; 15 | public static final int NATIVE_PORT = 9000; 16 | public static final int POSTGRESQL_PORT = 9005; 17 | 18 | public static final String NORMAL_STATEMENT = "normal"; 19 | public static final String PREPARED_STATEMENT = "prepared"; 20 | 21 | public static final String REUSE_CONNECTION = "reuse"; 22 | public static final String NEW_CONNECTION = "new"; 23 | 24 | // sample size used in 10k query/insert 25 | public static final int SAMPLE_SIZE = Integer.parseInt(System.getProperty("sampleSize", "10000")); 26 | // floating range(to reduce server-side cache hits) used in 10k query/insert 27 | public static final int FLOATING_RANGE = Integer.parseInt(System.getProperty("floatingRange", "100")); 28 | 29 | public static final String SAMPLES = SAMPLE_SIZE + " + ~" + FLOATING_RANGE; 30 | 31 | private Constants() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/client/ClientBenchmark.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark.client; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import org.openjdk.jmh.annotations.BenchmarkMode; 5 | import org.openjdk.jmh.annotations.Fork; 6 | import org.openjdk.jmh.annotations.Measurement; 7 | import org.openjdk.jmh.annotations.Mode; 8 | import org.openjdk.jmh.annotations.OutputTimeUnit; 9 | import org.openjdk.jmh.annotations.Scope; 10 | import org.openjdk.jmh.annotations.State; 11 | import org.openjdk.jmh.annotations.Threads; 12 | import org.openjdk.jmh.annotations.Warmup; 13 | 14 | /** 15 | * Base class for ClickHouse Java client benchmarking. 16 | */ 17 | @State(Scope.Benchmark) 18 | @Warmup(iterations = 10, timeUnit = TimeUnit.SECONDS, time = 1) 19 | @Measurement(iterations = 10, timeUnit = TimeUnit.SECONDS, time = 1) 20 | @Fork(value = 2) 21 | @Threads(value = -1) 22 | @BenchmarkMode(Mode.Throughput) 23 | @OutputTimeUnit(TimeUnit.SECONDS) 24 | public abstract class ClientBenchmark { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/client/Simple.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark.client; 2 | 3 | import java.util.concurrent.Future; 4 | import org.openjdk.jmh.annotations.Benchmark; 5 | import org.openjdk.jmh.infra.Blackhole; 6 | import com.clickhouse.client.ClickHouseResponse; 7 | 8 | public class Simple extends ClientBenchmark { 9 | @Benchmark 10 | public void insertOneRandomNumber(Blackhole blackhole, ClientState state) throws Throwable { 11 | Future future = state.newRequest().format(state.getFormat()) 12 | .query("insert into test_insert(i) values(" + state.getRandomSample() + ")").execute(); 13 | state.consume(blackhole, future); 14 | } 15 | 16 | @Benchmark 17 | public void selectOneRandomNumber(Blackhole blackhole, ClientState state) throws Throwable { 18 | Future future = state.newRequest().format(state.getFormat()) 19 | .query("select " + state.getRandomSample() + " as n").execute(); 20 | state.consume(blackhole, future); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/Basic.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark.jdbc; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.Statement; 5 | import java.util.Collections; 6 | import org.openjdk.jmh.annotations.Benchmark; 7 | 8 | public class Basic extends DriverBenchmark { 9 | @Benchmark 10 | public int insertOneRandomNumber(DriverState state) throws Throwable { 11 | final int num = state.getRandomSample(); 12 | 13 | return executeInsert(state, "insert into test_insert(i) values(?)", (p, v, l, i) -> p.setObject(i, v), 14 | Collections.enumeration(Collections.singletonList(new Object[] { num }))); 15 | } 16 | 17 | @Benchmark 18 | public int selectOneRandomNumber(DriverState state) throws Throwable { 19 | final int num = state.getRandomSample(); 20 | 21 | try (Statement stmt = executeQuery(state, "select ? as n", num); ResultSet rs = stmt.getResultSet();) { 22 | if (!rs.next() || num != rs.getInt(1)) { 23 | throw new IllegalStateException(); 24 | } 25 | 26 | return num; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/ConsumeValueFunction.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark.jdbc; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | import org.openjdk.jmh.infra.Blackhole; 7 | 8 | @FunctionalInterface 9 | public interface ConsumeValueFunction { 10 | void consume(Blackhole blackhole, ResultSet rs, int rowIndex, int columnIndex) throws SQLException; 11 | } 12 | -------------------------------------------------------------------------------- /clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/SupplyValueFunction.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark.jdbc; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.SQLException; 5 | 6 | @FunctionalInterface 7 | public interface SupplyValueFunction { 8 | void set(PreparedStatement ps, Object value, int rowIndex, int columnIndex) throws SQLException; 9 | } 10 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseDnsResolver.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import com.clickhouse.client.config.ClickHouseDefaults; 6 | import com.clickhouse.client.naming.SrvResolver; 7 | import com.clickhouse.data.ClickHouseUtils; 8 | import com.clickhouse.logging.Logger; 9 | import com.clickhouse.logging.LoggerFactory; 10 | 11 | /** 12 | * Default DNS resolver. It tries to look up service record (SRV record) when 13 | * {@link com.clickhouse.client.config.ClickHouseDefaults#SRV_RESOLVE} is set to 14 | * {@code true}. 15 | */ 16 | @Deprecated 17 | public class ClickHouseDnsResolver { 18 | private static final Logger log = LoggerFactory.getLogger(ClickHouseDnsResolver.class); 19 | 20 | private static final ClickHouseDnsResolver instance = ClickHouseUtils.getService(ClickHouseDnsResolver.class, 21 | new ClickHouseDnsResolver()); 22 | 23 | protected static ClickHouseDnsResolver newInstance() { 24 | ClickHouseDnsResolver resolver = null; 25 | 26 | if ((boolean) ClickHouseDefaults.SRV_RESOLVE.getEffectiveDefaultValue()) { 27 | try { 28 | resolver = new SrvResolver(); 29 | } catch (Throwable e) { 30 | log.warn("Failed to enable SRV resolver due to:", e); 31 | } 32 | } 33 | 34 | return resolver == null ? new ClickHouseDnsResolver() : resolver; 35 | } 36 | 37 | public static ClickHouseDnsResolver getInstance() { 38 | return instance; 39 | } 40 | 41 | public InetSocketAddress resolve(ClickHouseProtocol protocol, String host, int port) { 42 | return new InetSocketAddress(host, port); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseSocketFactory.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * Generic factory interface for creating sockets used by the TCP and Apache 7 | * Http clients. 8 | */ 9 | @Deprecated 10 | public interface ClickHouseSocketFactory { 11 | /** 12 | * Creates a new instance of the provided configuration and class type. 13 | * 14 | * @param type of class to create 15 | * @param config configuration 16 | * @param clazz class instance for the type to instantiate 17 | * @return non-null new instance of the given class 18 | * @throws IOException when failed to create the instance 19 | * @throws UnsupportedOperationException when the given class is not supported 20 | */ 21 | T create(ClickHouseConfig config, Class clazz) throws IOException, UnsupportedOperationException; 22 | 23 | /** 24 | * Tests whether this factory supports creating instances of the given class 25 | * type. For example, before calling {@link #create(ClickHouseConfig, Class)}, 26 | * you may want to call this method first to verify the factory can produce the 27 | * desired type. 28 | * 29 | * @param clazz non-null class reflecting the type to check support for 30 | * @return true if the factory supports creating instances of the given type; 31 | * false otherwise 32 | */ 33 | boolean supports(Class clazz); 34 | } 35 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseTransactionException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | @Deprecated 4 | public class ClickHouseTransactionException extends ClickHouseException { 5 | public static final int ERROR_INVALID_TRANSACTION = 649; 6 | public static final int ERROR_UNKNOWN_STATUS_OF_TRANSACTION = 659; 7 | 8 | private final ClickHouseTransaction tx; 9 | 10 | public ClickHouseTransactionException(String message, ClickHouseTransaction tx) { 11 | this(ERROR_INVALID_TRANSACTION, message, tx); 12 | } 13 | 14 | public ClickHouseTransactionException(String message, Throwable cause, ClickHouseTransaction tx) { 15 | this(ERROR_INVALID_TRANSACTION, message, cause, tx); 16 | } 17 | 18 | public ClickHouseTransactionException(int code, String message, Throwable cause, ClickHouseTransaction tx) { 19 | super(code, message, cause); 20 | this.tx = tx; 21 | } 22 | 23 | public ClickHouseTransactionException(int code, String message, ClickHouseTransaction tx) { 24 | super(code, message, tx.getServer()); 25 | this.tx = tx; 26 | } 27 | 28 | public ClickHouseTransaction getTransaction() { 29 | return tx; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/UnsupportedProtocolException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | @Deprecated 4 | public class UnsupportedProtocolException extends IllegalStateException { 5 | private final ClickHouseProtocol protocol; 6 | 7 | public UnsupportedProtocolException(ClickHouseProtocol protocol, String errorMessage) { 8 | super(errorMessage); 9 | 10 | this.protocol = protocol == null ? ClickHouseProtocol.ANY : protocol; 11 | } 12 | 13 | public ClickHouseProtocol getProtocol() { 14 | return protocol; 15 | } 16 | } -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/config/ClickHouseHealthCheckMethod.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.config; 2 | 3 | @Deprecated 4 | public enum ClickHouseHealthCheckMethod { 5 | /** 6 | * Ping is the protocol-specific approach for health check, which in general is 7 | * faster. 8 | */ 9 | PING, 10 | /** 11 | * Issue query "select 1" for health check, slightly slower compare to ping but 12 | * works the best with 3party tools. 13 | */ 14 | SELECT_ONE; 15 | } 16 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/config/ClickHouseProxyType.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.config; 2 | 3 | /** 4 | * Defines supported SSL mode. 5 | */ 6 | @Deprecated 7 | public enum ClickHouseProxyType { 8 | IGNORE, DIRECT, HTTP, SOCKS; 9 | } 10 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/config/ClickHouseSslMode.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.config; 2 | 3 | /** 4 | * Defines supported SSL mode. 5 | */ 6 | @Deprecated 7 | public enum ClickHouseSslMode { 8 | NONE, STRICT 9 | } 10 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/config/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides necessary classes to configure the client and/or request. 3 | */ 4 | package com.clickhouse.client.config; 5 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java/com/clickhouse/client/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides necessary classes to communicate with ClickHouse server. 3 | */ 4 | package com.clickhouse.client; 5 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java11/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse.client module. 3 | */ 4 | module com.clickhouse.client { 5 | exports com.clickhouse.client; 6 | exports com.clickhouse.client.config; 7 | 8 | requires static org.dnsjava; 9 | 10 | requires transitive com.clickhouse.data; 11 | 12 | uses com.clickhouse.client.ClickHouseClient; 13 | uses com.clickhouse.client.ClickHouseDnsResolver; 14 | uses com.clickhouse.client.ClickHouseSslContextProvider; 15 | } 16 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse.client module. 3 | */ 4 | module com.clickhouse.client { 5 | exports com.clickhouse.client; 6 | exports com.clickhouse.client.config; 7 | 8 | requires static org.dnsjava; 9 | 10 | requires transitive com.clickhouse.data; 11 | 12 | uses com.clickhouse.client.ClickHouseClient; 13 | uses com.clickhouse.client.ClickHouseDnsResolver; 14 | uses com.clickhouse.client.ClickHouseSslContextProvider; 15 | } 16 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-client/native-image.properties: -------------------------------------------------------------------------------- 1 | Args = -H:IncludeResources=${.}/resource-config.json 2 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-client/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources": { 3 | "includes": [ 4 | { 5 | "pattern": "\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" 6 | }, 7 | { 8 | "pattern": "\\QMETA-INF/services/com.clickhouse.client.ClickHouseSslContextProvider\\E" 9 | } 10 | ] 11 | }, 12 | "bundles": [] 13 | } 14 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/resources/META-INF/services/com.clickhouse.client.ClickHouseSslContextProvider: -------------------------------------------------------------------------------- 1 | com.clickhouse.client.config.ClickHouseDefaultSslContextProvider 2 | -------------------------------------------------------------------------------- /clickhouse-client/src/main/resources/clickhouse-client-version.properties: -------------------------------------------------------------------------------- 1 | version=${revision} 2 | build.date=${build_timestamp} -------------------------------------------------------------------------------- /clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseProtocolTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class ClickHouseProtocolTest { 7 | @Test(groups = { "unit" }) 8 | public void testUriScheme() { 9 | Assert.assertThrows(UnsupportedOperationException.class, 10 | () -> ClickHouseProtocol.GRPC.getUriSchemes().add("a")); 11 | Assert.assertThrows(UnsupportedOperationException.class, 12 | () -> ClickHouseProtocol.HTTP.getUriSchemes().remove(0)); 13 | 14 | for (ClickHouseProtocol p : ClickHouseProtocol.values()) { 15 | for (String s : p.getUriSchemes()) { 16 | Assert.assertEquals(ClickHouseProtocol.fromUriScheme(s), p); 17 | Assert.assertEquals(ClickHouseProtocol.fromUriScheme(s.toUpperCase()), p); 18 | Assert.assertEquals(ClickHouseProtocol.fromUriScheme(s + " "), ClickHouseProtocol.ANY); 19 | } 20 | } 21 | 22 | Assert.assertEquals(ClickHouseProtocol.fromUriScheme("gRPC"), ClickHouseProtocol.GRPC); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseSslContextProviderTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class ClickHouseSslContextProviderTest { 7 | @Test(groups = { "unit" }) 8 | public void testGetProvider() { 9 | Assert.assertNotNull(ClickHouseSslContextProvider.getProvider()); 10 | Assert.assertEquals(ClickHouseSslContextProvider.getProvider().getClass(), 11 | ClickHouseSslContextProvider.getProvider().getClass()); 12 | } 13 | } -------------------------------------------------------------------------------- /clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestClient.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | 5 | public class ClickHouseTestClient implements ClickHouseClient { 6 | private ClickHouseConfig clientConfig; 7 | 8 | @Override 9 | public boolean accept(ClickHouseProtocol protocol) { 10 | return true; 11 | } 12 | 13 | @Override 14 | public CompletableFuture execute(ClickHouseRequest request) { 15 | return CompletableFuture.supplyAsync(() -> null); 16 | } 17 | 18 | @Override 19 | public ClickHouseConfig getConfig() { 20 | return this.clientConfig; 21 | } 22 | 23 | @Override 24 | public void init(ClickHouseConfig config) { 25 | ClickHouseClient.super.init(config); 26 | 27 | this.clientConfig = config; 28 | } 29 | 30 | @Override 31 | public void close() { 32 | this.clientConfig = null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/java/com/clickhouse/client/config/ClickHouseDefaultSslContextProviderTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.config; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class ClickHouseDefaultSslContextProviderTest { 7 | @Test(groups = { "unit" }) 8 | public void testGetAlgorithm() { 9 | Assert.assertEquals(ClickHouseDefaultSslContextProvider.getAlgorithm("", null), null); 10 | Assert.assertEquals(ClickHouseDefaultSslContextProvider.getAlgorithm("---BEGIN ", "x"), "x"); 11 | Assert.assertEquals(ClickHouseDefaultSslContextProvider.getAlgorithm("---BEGIN PRIVATE KEY---", "x"), "x"); 12 | Assert.assertEquals(ClickHouseDefaultSslContextProvider.getAlgorithm("---BEGIN PRIVATE KEY---", "x"), "x"); 13 | Assert.assertEquals(ClickHouseDefaultSslContextProvider.getAlgorithm("-----BEGIN RSA PRIVATE KEY-----", ""), 14 | "RSA"); 15 | } 16 | 17 | @Test(groups = { "unit" }) 18 | public void testGetPrivateKey() throws Exception { 19 | // openssl genpkey -out pkey4test.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2048 20 | Assert.assertNotNull(ClickHouseDefaultSslContextProvider.getPrivateKey("pkey4test.pem")); 21 | } 22 | } -------------------------------------------------------------------------------- /clickhouse-client/src/test/java/com/clickhouse/client/naming/SrvResolverTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.naming; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import com.clickhouse.client.ClickHouseProtocol; 6 | 7 | import org.testng.Assert; 8 | import org.testng.annotations.Test; 9 | 10 | public class SrvResolverTest { 11 | @Test(groups = { "integration" }) 12 | public void testLookup() { 13 | String dns = "_sip._udp.sip.voice.google.com"; 14 | Assert.assertNotNull(new SrvResolver().lookup(dns, true)); 15 | Assert.assertNotNull(new SrvResolver().lookup(dns, false)); 16 | } 17 | 18 | @Test(groups = { "integration" }) 19 | public void testResolv() { 20 | String host = "_sip._udp.sip.voice.google.com"; 21 | int port = 5060; 22 | 23 | String dns = "_sip._udp.sip.voice.google.com"; 24 | Assert.assertEquals(new SrvResolver().resolve(ClickHouseProtocol.ANY, host, 0), 25 | new InetSocketAddress(host, port)); 26 | } 27 | } -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/META-INF/services/com.clickhouse.client.ClickHouseClient: -------------------------------------------------------------------------------- 1 | com.clickhouse.client.ClickHouseTestClient 2 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/README.md: -------------------------------------------------------------------------------- 1 | ### Root CA 2 | 3 | ```bash 4 | openssl genrsa -des3 -out myCA.key 4096 5 | openssl req -subj "/CN=localhost" -key myCA.key -days 36500 -nodes -x509 -keyout myCA.key -out myCA.crt 6 | ``` 7 | 8 | ### Server 9 | 10 | ```bash 11 | openssl req -nodes -subj "/CN=localhost.localdomain" -new -newkey rsa:2048 -keyout server.key -out server.csr 12 | openssl x509 -req -in server.csr -CA myCA.crt -CAkey myCA.key -CAcreateserial -out server.crt -days 36500 13 | ``` 14 | 15 | ### Client 16 | 17 | ```bash 18 | openssl req -nodes -subj "/CN=me" -newkey rsa:2048 -keyout client.key -out client.csr 19 | openssl x509 -req -in client.csr -out client.crt -CAcreateserial -CA myCA.crt -CAkey myCA.key -days 36500 20 | ``` 21 | 22 | ### Some_user 23 | 24 | ```bash 25 | openssl req -nodes -subj "/CN=some_user" -newkey rsa:2048 -keyout some_user.key -out some_user.csr 26 | openssl x509 -req -in some_user.csr -out some_user.crt -CAcreateserial -CA marsnet_ca.crt -CAkey marsnet_ca.key -days 36500 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/client.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDqjCCAZICFHA/CA4Wr4Sik2VhLbbP+W0PrMjiMA0GCSqGSIb3DQEBCwUAMBQx 3 | EjAQBgNVBAMMCWxvY2FsaG9zdDAgFw0yMzAzMTAxMjA4MjNaGA8yMTIzMDIxNDEy 4 | MDgyM1owDTELMAkGA1UEAwwCbWUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK 5 | AoIBAQChO5HIP1ePoCfbRhDYqH/czE3YWQ47OrzyLyNAHHckjEW/v41gCvMS6m44 6 | xKYmFWkG8vAVlJxsvPQLxvDdc+tpYwv9hdrZR2iJ6/dh2hmocZxNzEGtBCppdvhq 7 | w+8DWxxjCRiK7YoW1s2oSDjVRP5k315DkyKP90IJ2olUivL0Rex8nwdkF/WjMRVH 8 | D4Jfmf1MpctJL8vlhXvG1n05S5uj1RSudOU12aZLDNsFFsRq6q4+Fx2AsDgr4Jy/ 9 | IQHrtSxos7shkLvDfIIv7fzi1HniX/4nk4yyE324ot2mbBL93YllIe3VeyTq0xQu 10 | aYAgbNAd5ANm/Qa9dBCHrtoP0S5PAgMBAAEwDQYJKoZIhvcNAQELBQADggIBAAwB 11 | 37yTBqT0LaFdcXk5ioaiLQlKdpkQ8Ymg1JK2Q2RJJmt4wM3aHomMirgPAV0ek8dn 12 | oBhY57KWvTWxm5bNmqsPYP8VEAxO9HkMfWzX17SFIl6wqBqbrZKHEuS4Mo6u7eUc 13 | Vt1Q4VmX+vUP5A8ndJ1RNZ9fn9lIsg1wvtt8p45HCs0FYNSdpMTNp09wk+OBKqhi 14 | X0tBTjetI410O32VTGFWBDgV1/12/REoX3WEuOhrLhq8h8aPPWFgr5oNu/Qb9ge1 15 | OaSnGjaHzk1pEljeNJuX+k55HklrZan+YZhhvPSLU3FsPi0DTnAvcBtZECFGKYhJ 16 | UpA7ob1OrzmxNy45DbfbVyXtH2I8PxtyIbHVbHntQP35AvwH/6gibiGdvL6WWp/K 17 | +DcG9Y4+TLKc0BVyJBAhQTaG/2gZAh9y1LArsAmOy7A+6bOzb/Pc5r/PbON17TW5 18 | urLd08F58+4BJgXvsw6mR97DB/7pwS182ZBtbpl99H4ih567n+Lg6CgoM3UWPmiv 19 | TPP3r1/a+DFh/thv28mya4nZ6yVi1kJjyv4PsAso6DjcQBN+agKYuEpEQiLIpz4L 20 | 21qRfAdKWWWk87eHN2m8IkxTgh6NJFpTy8SN2dq50fWLzVvcqa116YU02EtwRwMK 21 | R1RThV+9j3tDcGo/rFm1/3PROfRvn866PfTgFpx4 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/containers/clickhouse-server/certs/KeyStore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/clickhouse-client/src/test/resources/containers/clickhouse-server/certs/KeyStore.jks -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/containers/clickhouse-server/certs/localhost.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsjCCAZoCFDf293LbOUODxdfLDjdTyo/S+dOhMA0GCSqGSIb3DQEBCwUAMBcx 3 | FTATBgNVBAMMDGxvY2FsaG9zdCBDQTAeFw0yMzA4MjgwNzQ4MjVaFw0yNDA4Mjcw 4 | NzQ4MjVaMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQAD 5 | ggEPADCCAQoCggEBAJNaI1WDThIEawIn9aqFu0n3tuCC3GXJ4Wu5t5SobrGWcTj2 6 | VmkQU9xaX5247qvofwOLUvfWHX4Ybq3gCKXI+WwsNYd8qICTEhjx3su4AZR02g3H 7 | ABkwcaW5HsGwJuv+5gyO7LD7GRVCSHOYN2r/tVZkmu2D53J3jUcxHEB6iwZB+FIo 8 | PhjZhBsypQEpZqbXd+Wl4YYlRClDO7hdRJLzKwyIhiKyMfvhgoTeM/pZpKbmH5a1 9 | X2SA4kLmhXtuSOUtASSkcBZFIdYOfA/Db0MVhYFmKJGUHNSU68snPRhrMdPf+zGo 10 | 78wHPfLT7gbnSSYCCqRI/nJ4WnAGynLWIDDkeoUCAwEAATANBgkqhkiG9w0BAQsF 11 | AAOCAQEAczBy/94o6Q57FdK5K05rcaLN5/Bdn1LxJMhIzgmtIsIVaPChBCBJLvL1 12 | mxR09oO48lnVrFD/q3QdkoG9thMrQ1N8WIKF1+It5eVjPQvKPYmbHPW4nc+y6c+I 13 | Rlb0DjzEG0AzoU5zBirJD7gBUANQIdFQJon+DEspvRmjrNwEFHOE17/LOEtV+rwN 14 | 720j7kS3RJicZZGyQkeKhw3kmZ4bNmQZMznxOUgvP6PAfqZumDzMEpWUcCO1kWfE 15 | tbrKW4Lemxn5QVuWjtcJjeEtiXHDMOAnnBr8enCtHvwkry1ZvGOFtL7glO4N+hOL 16 | wjma4L0fkCQn6v84/uaFaGSb93hNdQ== 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/containers/clickhouse-server/certs/localhost.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIChjCCAW4CAQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0B 3 | AQEFAAOCAQ8AMIIBCgKCAQEAk1ojVYNOEgRrAif1qoW7Sfe24ILcZcnha7m3lKhu 4 | sZZxOPZWaRBT3Fpfnbjuq+h/A4tS99YdfhhureAIpcj5bCw1h3yogJMSGPHey7gB 5 | lHTaDccAGTBxpbkewbAm6/7mDI7ssPsZFUJIc5g3av+1VmSa7YPncneNRzEcQHqL 6 | BkH4Uig+GNmEGzKlASlmptd35aXhhiVEKUM7uF1EkvMrDIiGIrIx++GChN4z+lmk 7 | puYflrVfZIDiQuaFe25I5S0BJKRwFkUh1g58D8NvQxWFgWYokZQc1JTryyc9GGsx 8 | 09/7MajvzAc98tPuBudJJgIKpEj+cnhacAbKctYgMOR6hQIDAQABoC0wKwYJKoZI 9 | hvcNAQkOMR4wHDAaBgNVHREEEzARgglsb2NhbGhvc3SHBH8AAAEwDQYJKoZIhvcN 10 | AQELBQADggEBAHp11BBMTVa80zd5npWYuKTkbY2VtRIgsxQXvb9HHBVtLnnXXRFB 11 | VYfaHNXVc43OJkXf3in9xLXNwlT9dmY5vWSrURq2UsrmV7Z2Hjki8bzu6jBwH5xJ 12 | PpsJIVwzBhb41mVA4cIx1Vj9s+iZB/MGkM3RhuNlQSRaFHO4ywKxP7OTMlHip8Qr 13 | 1t2g+l4RYWHJKaYW5rkESVnoxpwstrhHjKI+TTOpfaNFC+4/lqbg7he4VIUCLiKW 14 | xoReoDq88coEqrPjZhEcIvZM1B6XG0kc6yVlpLhDkfbbxwq0MXtzjSiaY6lHk2JU 15 | tKKgNt7VmxTXsgnANafCFjk1mfwNEdTwdic= 16 | -----END CERTIFICATE REQUEST----- 17 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/containers/clickhouse-server/certs/marsnet_ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDDzCCAfegAwIBAgIUZs4tx6XjGPDX7fuusRQGVkWTDVswDQYJKoZIhvcNAQEL 3 | BQAwFzEVMBMGA1UEAwwMbG9jYWxob3N0IENBMB4XDTIzMDgyODA3NDQzMloXDTI2 4 | MDgyNzA3NDQzMlowFzEVMBMGA1UEAwwMbG9jYWxob3N0IENBMIIBIjANBgkqhkiG 5 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn+/rnmo/JiAQn7BlJzkIeSPDR6T9HLsi1/DV 6 | L62dZnkUYZgNWDQ93Ke/CulQ2TTqrTXZZSO2fBemeL4xpKCZAyuzOB8BV7bL28TW 7 | 0cCQJv0kyHmG1cn3xMj/LFXSKRHW8nZIxhvKI8IukRkeMA3CQeUEDv09XcTGPlTU 8 | LuEUSK1Utadn4WAkVDoPRJ3Sf9TykiBXKr4mHbZHH+qMI8FU25FSO3lUOku9qdME 9 | 17dmOlMOwRK2fKwx27brN7zu4HMDKvbl6ui+NIRLCY2i3aKauVc8abaDKLaZWl6T 10 | xdVfpkcjJQklD8YQNXVslqJ0wZ/MLvRDeJxgqqFpbtsFkH5+qQIDAQABo1MwUTAd 11 | BgNVHQ4EFgQUePUptVsruld+TcBVRpjSmh2/MkMwHwYDVR0jBBgwFoAUePUptVsr 12 | uld+TcBVRpjSmh2/MkMwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC 13 | AQEAbgsTa6zQ6BgCcq6a2dVpEng7wPKABjpAJxK0XhvbVexgaHk/5A8aNmI5HTT5 14 | uJ8r+X/Qx7PGq4LafICsJdRbiXYXSzO3q6ahoSigRXfBj1kB1Mzba8hdtkbc4WOr 15 | N1Ku2KuvmPJy/nnG59KU+I7IccK+Jjliz3wfJlL6BT/wQgCPbnKigeodM2hCZyDQ 16 | eOs/XCus8zsGTCzljFxfmsd07qsegoAYWHOlyW/XV1URaVfc8HbaVcgB3JD2YXY/ 17 | uuY75a/iJuWThJOXDjzjTF0FvsL6eVlqi0pf/DRxWu9LVXxQVnrrKturceXu31ug 18 | sQ5pxX7pflPu4x2LG+HAaM3Dtg== 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/containers/clickhouse-server/patch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | SERVER_CONF_DIR="/etc/clickhouse-server" 6 | ROOT_ELEMENT="yandex" 7 | REPLACE_TO="clickhouse" 8 | 9 | if [ -n "$(grep 'yandex>' /entrypoint.sh >/dev/null)" ]; then 10 | ROOT_ELEMENT="clickhouse" 11 | REPLACE_TO="yandex" 12 | fi 13 | 14 | \cp -rfv "$(dirname $0)/." $SERVER_CONF_DIR 15 | find $SERVER_CONF_DIR -type f -name "*.xml" -exec sed -i -e "s|$ROOT_ELEMENT>|$REPLACE_TO>|g" {} \; || true 16 | 17 | if chown clickhouse:clickhouse -R /etc/clickhouse-server/certs; then 18 | echo "Ownership of /etc/clickhouse-server/certs changed successfully." 19 | else 20 | echo "Failed to change ownership of /etc/clickhouse-server/certs." 21 | fi 22 | 23 | /entrypoint.sh 24 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/empty.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/clickhouse-client/src/test/resources/empty.csv -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | org.slf4j.simpleLogger.log.com.clickhouse.client=info 3 | org.slf4j.simpleLogger.showDateTime=true 4 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z 5 | org.slf4j.simpleLogger.showThreadName=true 6 | org.slf4j.simpleLogger.showLogName=true 7 | org.slf4j.simpleLogger.showShortLogName=true 8 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/some_user.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICtDCCAZwCFBbI6UQK2g1r8o4XRXu+9wvQBHmnMA0GCSqGSIb3DQEBCwUAMBcx 3 | FTATBgNVBAMMDGxvY2FsaG9zdCBDQTAgFw0yNDEwMTAxNjM3MzhaGA8yMTI0MDkx 4 | NjE2MzczOFowFDESMBAGA1UEAwwJc29tZV91c2VyMIIBIjANBgkqhkiG9w0BAQEF 5 | AAOCAQ8AMIIBCgKCAQEA68bBZlvBT64suwLa61eob9roTVXlJQmB9tGvX2cnJacP 6 | NBx2h6W8Ow43doRLBRt32SopV06O1i2c0L84pRoliJcGrUhKyxAsVxVv11mFd4qg 7 | 962TeYe3VawSKK2w83GNfVhjQFwuNEDuzJT0I7J0jH/uNclMxAtFZNkKVMA2GOK2 8 | c3Pib8zCmqITWAX5XXWUUvS0LWsASaBAEVh4R7StYbDl0L3VeiHCw6fKpdevVfw5 9 | eDb+KuwMUOCPak0v31izEsXtcAyc7hxEZLfUMA+00zAdUENTC38GOJNTqirg0YmD 10 | +wxPdp3quWwkF/b831UTczAHkK7GP3swPjfciMN8nwIDAQABMA0GCSqGSIb3DQEB 11 | CwUAA4IBAQB+1poCA9p/XyKf5jxnAkaZQzoRW+fNqZvz8Eld2gGLqw7ZZUiBW6zo 12 | d4aCAeuNehw5zJEOf1ew5EZzdWYRdxXUarjs3HOSQalfYTS8HqNI19sgWYD6Zcx+ 13 | sygJqswtplvPAB6phk9zyhQDLFNuJ8dp28xRgGuywYtVMnvLG1wapPf/fnqkRcOW 14 | yTBS4BBvtmzKPzMMZl/qB4Ol/STgVphceMFmI71HQQFUPb56E5tAQ+m3fezjdAJ2 15 | gZ+/LsApHLwhEV0ZGyIe/MNx0nDrkfWYWa7BsqvG6uuxyPXxgXSQofNjJN+RahRm 16 | oHREhAYRL40BS1F20aLRFRupzLJngLBh 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /clickhouse-client/src/test/resources/some_user.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICWTCCAUECAQAwFDESMBAGA1UEAwwJc29tZV91c2VyMIIBIjANBgkqhkiG9w0B 3 | AQEFAAOCAQ8AMIIBCgKCAQEA68bBZlvBT64suwLa61eob9roTVXlJQmB9tGvX2cn 4 | JacPNBx2h6W8Ow43doRLBRt32SopV06O1i2c0L84pRoliJcGrUhKyxAsVxVv11mF 5 | d4qg962TeYe3VawSKK2w83GNfVhjQFwuNEDuzJT0I7J0jH/uNclMxAtFZNkKVMA2 6 | GOK2c3Pib8zCmqITWAX5XXWUUvS0LWsASaBAEVh4R7StYbDl0L3VeiHCw6fKpdev 7 | Vfw5eDb+KuwMUOCPak0v31izEsXtcAyc7hxEZLfUMA+00zAdUENTC38GOJNTqirg 8 | 0YmD+wxPdp3quWwkF/b831UTczAHkK7GP3swPjfciMN8nwIDAQABoAAwDQYJKoZI 9 | hvcNAQELBQADggEBAA6cpW7rdV0a8FDxEBfZoStJPEVUisqS5pUT43UjFJ7M55kC 10 | LGQ9Vl2Ua0nA4BwX5Le/IWVwwnhnnIJWvoPEbka9TWBVGujOPvt/WwBbEN2yHgGD 11 | QgFrIq/zOaFVj3J3EuJtIXL2jOylDK14j+2k4MN4OJobVtQhyUHpmRTPgq4EVJIw 12 | /PU6Lltgr2V4pTs3m9Ey2pIHF04HQIzr6Tt6MRJkKGEYWvOZlYuCbXA5bPLMyq5g 13 | rs0kC1DMF5C3VsBND8oGQt0ULbc2AQy6AFJegdD/ZT+d4eeh+ejymc0nmB+kbxaM 14 | tAxp2yTsRKUsGu7TBeMY1DxoP1xG5lAHkGznESg= 15 | -----END CERTIFICATE REQUEST----- 16 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/config/ClickHouseBufferingMode.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.config; 2 | 3 | /** 4 | * Supported buffering mode for dealing with request and response. 5 | */ 6 | @Deprecated 7 | public enum ClickHouseBufferingMode { 8 | // TODO Adaptive / Dynamic 9 | 10 | /** 11 | * Resource-efficient mode provides reasonable performance with least CPU and 12 | * memory usage, which makes it ideal as default mode. Only buffer size is 13 | * considered in this mode, no queue is used for buffering. 14 | */ 15 | RESOURCE_EFFICIENT, 16 | /** 17 | * Custom mode allows you to customize buffer size and queue to balance resource 18 | * utilization and desired performance. 19 | */ 20 | CUSTOM, 21 | /** 22 | * Performance mode provides best performance at the cost of more CPU and much 23 | * much more memory usage - almost everything is loaded into working memory. 24 | */ 25 | PERFORMANCE 26 | } 27 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/config/ClickHouseDefaultOption.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.config; 2 | 3 | import java.io.Serializable; 4 | import java.util.Locale; 5 | 6 | import com.clickhouse.data.ClickHouseChecker; 7 | 8 | @Deprecated 9 | public final class ClickHouseDefaultOption implements ClickHouseOption { 10 | private final String name; 11 | private final String key; 12 | private final Serializable defaultValue; 13 | private final Class clazz; 14 | private final boolean sensitive; 15 | 16 | public ClickHouseDefaultOption(String name, T defaultValue) { 17 | this(name, defaultValue, false); 18 | } 19 | 20 | public ClickHouseDefaultOption(String name, T defaultValue, boolean sensitive) { 21 | this.name = ClickHouseChecker.nonNull(name, "name").toUpperCase(Locale.ROOT); 22 | this.key = name.toLowerCase(Locale.ROOT); 23 | this.defaultValue = ClickHouseChecker.nonNull(defaultValue, "defaultValue"); 24 | this.clazz = defaultValue.getClass(); 25 | this.sensitive = sensitive; 26 | } 27 | 28 | @Override 29 | public Serializable getDefaultValue() { 30 | return defaultValue; 31 | } 32 | 33 | @Override 34 | public String getDescription() { 35 | return ""; 36 | } 37 | 38 | @Override 39 | public String getKey() { 40 | return key; 41 | } 42 | 43 | @Override 44 | public Class getValueType() { 45 | return clazz; 46 | } 47 | 48 | @Override 49 | public boolean isSensitive() { 50 | return sensitive; 51 | } 52 | 53 | @Override 54 | public String name() { 55 | return name; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/config/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides configuration classes. 3 | */ 4 | package com.clickhouse.config; 5 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseDataUpdater.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * This class defines custom reading/writing logic, which can be used in 7 | * {@link ClickHouseInputStream#readCustom(ClickHouseDataUpdater)} and 8 | * {@link ClickHouseOutputStream#writeCustom(ClickHouseDataUpdater)}. 9 | */ 10 | @Deprecated 11 | @FunctionalInterface 12 | public interface ClickHouseDataUpdater { 13 | /** 14 | * Byte array(from {@code position} to {@code limit}) to update, usually read or 15 | * write. 16 | * 17 | * @param bytes non-null byte array to update 18 | * @param position zero-based index indicating start position of the byte array 19 | * @param limit zero-based index indicating end position of the byte array, 20 | * it should always greater than or equal to {@code position} 21 | * @return negative number, usually -1, indicates to more to update, or other 22 | * number for bytes being updated 23 | * @throws IOException when it failed to update 24 | */ 25 | int update(byte[] bytes, int position, int limit) throws IOException; 26 | } 27 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseRecordTransformer.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | @FunctionalInterface 4 | @Deprecated 5 | public interface ClickHouseRecordTransformer { 6 | /** 7 | * Updates values in the given record. 8 | * 9 | * @param rowIndex zero-based index of row 10 | * @param r record to update 11 | */ 12 | void update(int rowIndex, ClickHouseRecord r); 13 | } 14 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseStreamConfig.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | @Deprecated 4 | public interface ClickHouseStreamConfig { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseWriter.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | import java.io.IOException; 4 | 5 | @Deprecated 6 | @FunctionalInterface 7 | public interface ClickHouseWriter { 8 | static final String TYPE_NAME = "Writer"; 9 | 10 | /** 11 | * Writes data to output stream. 12 | * 13 | * @param output non-null output stream 14 | * @throws IOException when failed to write data to output stream 15 | */ 16 | void write(ClickHouseOutputStream output) throws IOException; 17 | } 18 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/format/tsv/ArrayByteFragment.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.format.tsv; 2 | 3 | @Deprecated 4 | public final class ArrayByteFragment extends ByteFragment { 5 | 6 | private ArrayByteFragment(byte[] buf, int start, int len) { 7 | super(buf, start, len); 8 | } 9 | 10 | public static ArrayByteFragment wrap(ByteFragment fragment) { 11 | return new ArrayByteFragment(fragment.buf, fragment.start, fragment.len); 12 | } 13 | 14 | @Override 15 | public boolean isNull() { 16 | // NULL 17 | return len == 4 && buf[start] == 'N' && buf[start + 1] == 'U' && buf[start + 2] == 'L' && buf[start + 3] == 'L'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/format/tsv/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides necessary classes to handle TSV format. 3 | */ 4 | package com.clickhouse.data.format.tsv; 5 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/mapper/IterableRecordWrapper.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.mapper; 2 | 3 | import java.util.Iterator; 4 | import java.util.List; 5 | 6 | import com.clickhouse.data.ClickHouseColumn; 7 | import com.clickhouse.data.ClickHouseDataConfig; 8 | import com.clickhouse.data.ClickHouseRecord; 9 | import com.clickhouse.data.ClickHouseRecordMapper; 10 | 11 | @Deprecated 12 | public final class IterableRecordWrapper implements Iterator { 13 | private final ClickHouseDataConfig config; 14 | private final List columns; 15 | private final Iterator records; 16 | private final Class objClass; 17 | private final T template; 18 | 19 | private ClickHouseRecordMapper mapper; 20 | 21 | public IterableRecordWrapper(ClickHouseDataConfig config, List columns, 22 | Iterator records, Class objClass, T template) { 23 | if (columns == null || records == null || objClass == null) { 24 | throw new IllegalArgumentException("Non-null column list, records and object class are required"); 25 | } 26 | this.config = config; 27 | this.columns = columns; 28 | this.records = records; 29 | this.objClass = objClass; 30 | this.template = template; 31 | } 32 | 33 | @Override 34 | public boolean hasNext() { 35 | return records.hasNext(); 36 | } 37 | 38 | @Override 39 | public T next() { 40 | if (mapper == null) { 41 | mapper = ClickHouseRecordMapper.of(config, columns, objClass); 42 | } 43 | return mapper.mapTo(records.next(), objClass, template); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/mapper/WrappedMapper.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.mapper; 2 | 3 | import java.util.List; 4 | 5 | import com.clickhouse.data.ClickHouseColumn; 6 | import com.clickhouse.data.ClickHouseDataConfig; 7 | import com.clickhouse.data.ClickHouseRecordMapper; 8 | 9 | @Deprecated 10 | public interface WrappedMapper { 11 | ClickHouseRecordMapper get(ClickHouseDataConfig config, List columns); 12 | } -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/ByteArrayQueueInputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import com.clickhouse.data.ClickHouseByteBuffer; 4 | import com.clickhouse.data.ClickHouseChecker; 5 | 6 | import java.io.IOException; 7 | import java.util.Queue; 8 | 9 | @Deprecated 10 | public class ByteArrayQueueInputStream extends AbstractByteArrayInputStream { 11 | 12 | private final Queue queue; 13 | 14 | public ByteArrayQueueInputStream(Queue queue, Runnable postCloseAction) { 15 | super(null, null, postCloseAction); 16 | this.queue = ClickHouseChecker.nonNull(queue, "queue");; 17 | } 18 | 19 | @Override 20 | protected int updateBuffer() throws IOException { 21 | position = 0; 22 | 23 | while (!queue.isEmpty()) { 24 | byte[] bytes = queue.poll(); 25 | int len = bytes != null ? bytes.length : 0; 26 | if (len > 0) { 27 | buffer = bytes; 28 | if (copyTo != null) { 29 | copyTo.write(bytes); 30 | } 31 | return limit = len; 32 | } 33 | } 34 | 35 | buffer = ClickHouseByteBuffer.EMPTY_BYTES; 36 | return limit = 0; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/DeferredInputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import com.clickhouse.data.ClickHouseDeferredValue; 7 | 8 | @Deprecated 9 | public final class DeferredInputStream extends InputStream { 10 | private final ClickHouseDeferredValue ref; 11 | private InputStream in; 12 | 13 | protected InputStream getInput() { 14 | return in != null ? in : (in = ref.get()); 15 | } 16 | 17 | public DeferredInputStream(ClickHouseDeferredValue in) { 18 | this.ref = in; 19 | this.in = null; 20 | } 21 | 22 | @Override 23 | public int available() throws IOException { 24 | return getInput().available(); 25 | } 26 | 27 | @Override 28 | public void close() throws IOException { 29 | getInput().close(); 30 | } 31 | 32 | @Override 33 | public int read() throws IOException { 34 | return getInput().read(); 35 | } 36 | 37 | @Override 38 | public int read(byte[] b) throws IOException { 39 | return getInput().read(b); 40 | } 41 | 42 | @Override 43 | public int read(byte[] b, int off, int len) throws IOException { 44 | return getInput().read(b, off, len); 45 | } 46 | 47 | @Override 48 | public long skip(long n) throws IOException { 49 | return getInput().skip(n); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/DeferredOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | import com.clickhouse.data.ClickHouseDeferredValue; 7 | 8 | @Deprecated 9 | public final class DeferredOutputStream extends OutputStream { 10 | private final ClickHouseDeferredValue ref; 11 | private OutputStream out; 12 | 13 | protected OutputStream getOutput() { 14 | return out != null ? out : (out = ref.get()); 15 | } 16 | 17 | public DeferredOutputStream(ClickHouseDeferredValue out) { 18 | this.ref = out; 19 | this.out = null; 20 | } 21 | 22 | @Override 23 | public void close() throws IOException { 24 | getOutput().close(); 25 | } 26 | 27 | @Override 28 | public void write(int b) throws IOException { 29 | getOutput().write(b); 30 | } 31 | 32 | @Override 33 | public void write(byte[] b, int off, int len) throws IOException { 34 | getOutput().write(b, off, len); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/EmptyOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import java.io.IOException; 4 | 5 | import com.clickhouse.data.ClickHouseDataUpdater; 6 | import com.clickhouse.data.ClickHouseOutputStream; 7 | 8 | /** 9 | * Empty output stream consumes nothing and it can never be closed. 10 | */ 11 | @Deprecated 12 | public final class EmptyOutputStream extends ClickHouseOutputStream { 13 | public static final EmptyOutputStream INSTANCE = new EmptyOutputStream(); 14 | 15 | private EmptyOutputStream() { 16 | super(null, null); 17 | } 18 | 19 | @Override 20 | public boolean isClosed() { 21 | return false; 22 | } 23 | 24 | @Override 25 | public void close() throws IOException { 26 | // do nothing 27 | } 28 | 29 | @Override 30 | public ClickHouseOutputStream transferBytes(byte[] bytes, int offset, int length) throws IOException { 31 | return this; 32 | } 33 | 34 | @Override 35 | public ClickHouseOutputStream writeByte(byte b) throws IOException { 36 | return this; 37 | } 38 | 39 | @Override 40 | public ClickHouseOutputStream writeBytes(byte[] bytes, int offset, int length) throws IOException { 41 | return this; 42 | } 43 | 44 | @Override 45 | public ClickHouseOutputStream writeCustom(ClickHouseDataUpdater writer) throws IOException { 46 | return this; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/IterableByteArrayInputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import java.io.IOException; 4 | import java.util.Iterator; 5 | 6 | import com.clickhouse.data.ClickHouseByteBuffer; 7 | import com.clickhouse.data.ClickHouseChecker; 8 | 9 | @Deprecated 10 | public class IterableByteArrayInputStream extends AbstractByteArrayInputStream { 11 | private final Iterator it; 12 | 13 | public IterableByteArrayInputStream(Iterable source, Runnable postCloseAction) { 14 | super(null, null, postCloseAction); 15 | 16 | it = ClickHouseChecker.nonNull(source, "Source").iterator(); 17 | } 18 | 19 | @Override 20 | protected int updateBuffer() throws IOException { 21 | position = 0; 22 | 23 | while (it.hasNext()) { 24 | byte[] bytes = it.next(); 25 | int len = bytes != null ? bytes.length : 0; 26 | if (len > 0) { 27 | buffer = bytes; 28 | if (copyTo != null) { 29 | copyTo.write(bytes); 30 | } 31 | return limit = len; 32 | } 33 | } 34 | 35 | buffer = ClickHouseByteBuffer.EMPTY_BYTES; 36 | return limit = 0; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/IterableByteBufferInputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import java.io.IOException; 4 | import java.nio.Buffer; 5 | import java.nio.ByteBuffer; 6 | import java.util.Iterator; 7 | 8 | import com.clickhouse.data.ClickHouseByteBuffer; 9 | import com.clickhouse.data.ClickHouseChecker; 10 | 11 | @Deprecated 12 | public class IterableByteBufferInputStream extends AbstractByteBufferInputStream { 13 | private final Iterator it; 14 | 15 | public IterableByteBufferInputStream(Iterable source, Runnable postCloseAction) { 16 | super(null, null, postCloseAction); 17 | 18 | it = ClickHouseChecker.nonNull(source, "Source").iterator(); 19 | } 20 | 21 | @Override 22 | protected int updateBuffer() throws IOException { 23 | while (it.hasNext()) { 24 | ByteBuffer bytes = it.next(); 25 | if (bytes != null && bytes.hasRemaining()) { 26 | buffer = bytes; 27 | if (copyTo != null) { 28 | int position = bytes.position(); 29 | if (bytes.hasArray()) { 30 | copyTo.write(bytes.array(), position, bytes.remaining()); 31 | } else { 32 | byte[] b = new byte[bytes.remaining()]; 33 | bytes.get(b); 34 | copyTo.write(b); 35 | ((Buffer) bytes).position(position); 36 | } 37 | } 38 | return bytes.remaining(); 39 | } 40 | } 41 | buffer = ClickHouseByteBuffer.EMPTY_BUFFER; 42 | return 0; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/IterableObjectInputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import java.io.IOException; 4 | import java.util.Iterator; 5 | import java.util.function.Function; 6 | 7 | import com.clickhouse.data.ClickHouseByteBuffer; 8 | import com.clickhouse.data.ClickHouseChecker; 9 | 10 | @Deprecated 11 | public class IterableObjectInputStream extends AbstractByteArrayInputStream { 12 | private final Function func; 13 | private final Iterator it; 14 | 15 | public IterableObjectInputStream(Iterable source, Function converter, Runnable postCloseAction) { 16 | super(null, null, postCloseAction); 17 | 18 | func = ClickHouseChecker.nonNull(converter, "Converter"); 19 | it = ClickHouseChecker.nonNull(source, "Source").iterator(); 20 | } 21 | 22 | @Override 23 | protected int updateBuffer() throws IOException { 24 | position = 0; 25 | while (it.hasNext()) { 26 | T obj = it.next(); 27 | byte[] bytes = obj != null ? func.apply(obj) : null; 28 | if (bytes != null && bytes.length > 0) { 29 | buffer = bytes; 30 | if (copyTo != null) { 31 | copyTo.write(bytes); 32 | } 33 | return limit = bytes.length; 34 | } 35 | } 36 | buffer = ClickHouseByteBuffer.EMPTY_BYTES; 37 | return limit = 0; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/stream/WrappedOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | import com.clickhouse.data.ClickHouseChecker; 7 | import com.clickhouse.data.ClickHouseDataConfig; 8 | import com.clickhouse.data.ClickHousePassThruStream; 9 | 10 | /** 11 | * Wrapper of {@link java.io.OutputStream}. 12 | */ 13 | @Deprecated 14 | public class WrappedOutputStream extends AbstractByteArrayOutputStream { 15 | private final OutputStream output; 16 | 17 | @Override 18 | protected void flushBuffer(byte[] bytes, int offset, int length) throws IOException { 19 | output.write(bytes, offset, length); 20 | } 21 | 22 | public WrappedOutputStream(ClickHousePassThruStream stream, OutputStream out, int bufferSize, 23 | Runnable postCloseAction) { 24 | super(stream, ClickHouseDataConfig.getBufferSize(bufferSize), postCloseAction); 25 | 26 | output = ClickHouseChecker.nonNull(out, "OutputStream"); 27 | } 28 | 29 | @Override 30 | public void flush() throws IOException { 31 | ensureOpen(); 32 | 33 | if (position > 0) { 34 | flushBuffer(); 35 | } 36 | output.flush(); 37 | } 38 | 39 | @Override 40 | public void close() throws IOException { 41 | if (!closed) { 42 | try { 43 | // flush before closing the inner output stream 44 | super.close(); 45 | } finally { 46 | output.close(); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/data/value/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides necessary classes to handle different format or type of data. 3 | */ 4 | package com.clickhouse.data.value; 5 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/logging/JdkLoggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.logging; 2 | 3 | /** 4 | * Adaptor of JDK logger factory. 5 | */ 6 | @Deprecated 7 | public class JdkLoggerFactory extends LoggerFactory { 8 | @Override 9 | public Logger get(String name) { 10 | return new JdkLogger(java.util.logging.Logger.getLogger(name)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/logging/Slf4jLoggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.logging; 2 | 3 | /** 4 | * Adaptor of slf4j logger factory. 5 | */ 6 | @Deprecated 7 | public class Slf4jLoggerFactory extends LoggerFactory { 8 | @Override 9 | public Logger get(Class clazz) { 10 | return new Slf4jLogger(org.slf4j.LoggerFactory.getLogger(clazz)); 11 | } 12 | 13 | @Override 14 | public Logger get(String name) { 15 | return new Slf4jLogger(org.slf4j.LoggerFactory.getLogger(name)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java/com/clickhouse/logging/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides logging classes. 3 | */ 4 | @Deprecated 5 | package com.clickhouse.logging; 6 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java11/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse.data module. 3 | */ 4 | module com.clickhouse.data { 5 | exports com.clickhouse.config; 6 | exports com.clickhouse.data; 7 | // exports com.clickhouse.data.cache; 8 | // exports com.clickhouse.data.format; 9 | // exports com.clickhouse.data.mapper; 10 | // exports com.clickhouse.data.stream; 11 | exports com.clickhouse.data.value; 12 | exports com.clickhouse.logging; 13 | 14 | requires static java.logging; 15 | requires static com.google.gson; 16 | requires static com.github.benmanes.caffeine; 17 | requires static org.lz4.java; 18 | requires static org.slf4j; 19 | requires static org.roaringbitmap; 20 | 21 | uses com.clickhouse.data.ClickHouseDataStreamFactory; 22 | uses com.clickhouse.logging.LoggerFactory; 23 | } 24 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse.data module. 3 | */ 4 | module com.clickhouse.data { 5 | exports com.clickhouse.config; 6 | exports com.clickhouse.data; 7 | // exports com.clickhouse.data.cache; 8 | // exports com.clickhouse.data.format; 9 | // exports com.clickhouse.data.mapper; 10 | // exports com.clickhouse.data.stream; 11 | exports com.clickhouse.data.value; 12 | exports com.clickhouse.logging; 13 | 14 | requires static java.logging; 15 | requires static com.google.gson; 16 | requires static com.github.benmanes.caffeine; 17 | requires static org.lz4.java; 18 | requires static org.slf4j; 19 | requires static org.roaringbitmap; 20 | 21 | uses com.clickhouse.data.ClickHouseDataStreamFactory; 22 | uses com.clickhouse.logging.LoggerFactory; 23 | } 24 | -------------------------------------------------------------------------------- /clickhouse-data/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-data/native-image.properties: -------------------------------------------------------------------------------- 1 | Args = --initialize-at-build-time=com.clickhouse.data.ClickHouseFormat 2 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/ClickHouseCompressionAlgorithmTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class ClickHouseCompressionAlgorithmTest { 7 | @Test(groups = { "unit" }) 8 | public void testCreateInstance() { 9 | for (ClickHouseCompression c : ClickHouseCompression.values()) { 10 | ClickHouseCompressionAlgorithm alg = ClickHouseCompressionAlgorithm.of(c); 11 | Assert.assertNotNull(alg); 12 | Assert.assertEquals(alg.getAlgorithm(), c); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/ClickHouseDataConfigTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class ClickHouseDataConfigTest { 7 | @Test(groups = { "unit" }) 8 | public void testGetBufferSize() { 9 | int[] values = new int[] { -1, 0 }; 10 | for (int i : values) { 11 | for (int j : values) { 12 | for (int k : values) { 13 | Assert.assertEquals(ClickHouseDataConfig.getBufferSize(i, j, k), 14 | ClickHouseDataConfig.DEFAULT_BUFFER_SIZE); 15 | } 16 | } 17 | } 18 | 19 | for (int i : values) { 20 | Assert.assertEquals(ClickHouseDataConfig.getBufferSize(i, 3, 2), 2); 21 | } 22 | Assert.assertEquals(ClickHouseDataConfig.getBufferSize(1, 3, 2), 1); 23 | Assert.assertEquals(ClickHouseDataConfig.getBufferSize(3, 2, 1), 1); 24 | Assert.assertEquals(ClickHouseDataConfig.getBufferSize(3, 1, 2), 2); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/TestServiceImplementation.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | public class TestServiceImplementation implements TestServiceInterface { 4 | @Override 5 | public String getValue() { 6 | return TestServiceImplementation.class.getSimpleName(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/TestServiceInterface.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | public interface TestServiceInterface { 4 | default String getValue() { 5 | return TestServiceInterface.class.getSimpleName(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/cache/JdkLruCacheTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.cache; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.clickhouse.data.ClickHouseCache; 7 | 8 | import org.testng.Assert; 9 | import org.testng.annotations.Test; 10 | 11 | public class JdkLruCacheTest { 12 | @Test(groups = { "unit" }) 13 | public void testCache() { 14 | int capacity = 3; 15 | ClickHouseCache cache = JdkLruCache.create(capacity, (k) -> k); 16 | Assert.assertNotNull(cache); 17 | 18 | Map map = (Map) cache.unwrap(Map.class); 19 | Assert.assertNotNull(map); 20 | Assert.assertEquals(map.size(), 0); 21 | 22 | Map m = new HashMap<>(); 23 | m.put("A", "A"); 24 | m.put("B", "B"); 25 | m.put("C", "C"); 26 | Assert.assertEquals(cache.get("A"), "A"); 27 | Assert.assertEquals(map.size(), 1); 28 | Assert.assertEquals(cache.get("B"), "B"); 29 | Assert.assertEquals(map.size(), 2); 30 | Assert.assertEquals(cache.get("C"), "C"); 31 | Assert.assertEquals(map.size(), 3); 32 | Assert.assertEquals(map, m); 33 | Assert.assertEquals(cache.get("D"), "D"); 34 | Assert.assertEquals(map.size(), 3); 35 | Assert.assertNotEquals(map, m); 36 | m.remove("A"); 37 | m.put("D", "D"); 38 | Assert.assertEquals(map, m); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/stream/IterableByteArrayInputStreamTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.stream; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | import java.util.LinkedList; 7 | import java.util.Queue; 8 | 9 | public class IterableByteArrayInputStreamTests { 10 | 11 | @Test(groups = { "unit" }) 12 | public void testIterableByteArrayInputStream() throws Exception { 13 | LinkedList buffers = new LinkedList<>(); 14 | buffers.add("Hello".getBytes()); 15 | buffers.add("World".getBytes()); 16 | IterableByteArrayInputStream is = new IterableByteArrayInputStream(buffers, null); 17 | byte[] buffer = new byte[5]; 18 | is.read(buffer, 0, 5); 19 | Assert.assertEquals(new String(buffer), "Hello"); 20 | is.read(buffer, 0, 5); 21 | Assert.assertEquals(new String(buffer) ,"World"); 22 | is.close(); 23 | } 24 | 25 | @Test(groups = { "unit" }) 26 | public void testByteArrayQueueInputStream() throws Exception { 27 | Queue buffers = new LinkedList<>(); 28 | buffers.add("Hello".getBytes()); 29 | buffers.add("World".getBytes()); 30 | ByteArrayQueueInputStream is = new ByteArrayQueueInputStream(buffers, null); 31 | byte[] buffer = new byte[5]; 32 | is.read(buffer, 0, 5); 33 | Assert.assertEquals(new String(buffer), "Hello"); 34 | is.read(buffer, 0, 5); 35 | Assert.assertEquals(new String(buffer) ,"World"); 36 | Assert.assertTrue(buffers.isEmpty()); 37 | is.close(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/value/WriterFunction.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.value; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | @FunctionalInterface 7 | public interface WriterFunction { 8 | void write(OutputStream o) throws IOException; 9 | } 10 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/value/array/ClickHouseByteArrayValueTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.value.array; 2 | 3 | import org.junit.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class ClickHouseByteArrayValueTest { 7 | @Test(groups = { "unit" }) 8 | public void testConvertToBoolean() { 9 | ClickHouseByteArrayValue v = ClickHouseByteArrayValue 10 | .of(new byte[] { 0, 1, -1 }); 11 | Assert.assertArrayEquals(v.getValue(), new byte[] { 0, 1, -1 }); 12 | Assert.assertArrayEquals(v.asArray(Boolean.class), new Boolean[] { false, true, false }); 13 | } 14 | 15 | @Test(groups = { "unit" }) 16 | public void testConvertFromBoolean() { 17 | ClickHouseByteArrayValue v = ClickHouseByteArrayValue.ofEmpty(); 18 | Assert.assertArrayEquals(v.getValue(), new byte[0]); 19 | v.update(new boolean[] { false, true, false }); 20 | Assert.assertArrayEquals(v.getValue(), new byte[] { 0, 1, 0 }); 21 | v.resetToNullOrEmpty(); 22 | Assert.assertArrayEquals(v.getValue(), new byte[0]); 23 | v.update(new Boolean[] { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE }); 24 | Assert.assertArrayEquals(v.getValue(), new byte[] { 0, 0, 1 }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/data/value/array/ClickHouseLongArrayValueTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data.value.array; 2 | 3 | import java.math.BigInteger; 4 | 5 | import org.junit.Assert; 6 | import org.testng.annotations.Test; 7 | 8 | public class ClickHouseLongArrayValueTest { 9 | @Test(groups = { "unit" }) 10 | public void testConvertToBigInteger() { 11 | ClickHouseLongArrayValue v = ClickHouseLongArrayValue 12 | .of(new long[] { 1L, new BigInteger("9223372036854775808").longValue() }); 13 | Assert.assertArrayEquals(v.getValue(), new long[] { 1L, -9223372036854775808L }); 14 | Assert.assertArrayEquals(v.asArray(BigInteger.class), 15 | new BigInteger[] { BigInteger.ONE, new BigInteger("9223372036854775808") }); 16 | } 17 | 18 | @Test(groups = { "unit" }) 19 | public void testConvertFromBigInteger() { 20 | ClickHouseLongArrayValue v = ClickHouseLongArrayValue.ofEmpty(); 21 | Assert.assertArrayEquals(v.getValue(), new long[0]); 22 | v.update(new BigInteger[] { BigInteger.ONE, new BigInteger("9223372036854775808") }); 23 | Assert.assertArrayEquals(v.getValue(), new long[] { 1L, -9223372036854775808L }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/logging/JdkLoggerTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.logging; 2 | 3 | import java.util.Collections; 4 | import org.testng.annotations.Test; 5 | 6 | public class JdkLoggerTest extends LoggerTest { 7 | private final JdkLoggerFactory factory = new JdkLoggerFactory(); 8 | 9 | @Override 10 | protected Logger getLogger(Class clazz) { 11 | return factory.get(clazz); 12 | } 13 | 14 | @Override 15 | protected Logger getLogger(String name) { 16 | return factory.get(name); 17 | } 18 | 19 | @Test(groups = { "unit" }) 20 | public void testInstantiation() { 21 | checkInstance(JdkLogger.class); 22 | } 23 | 24 | @Test(groups = { "unit" }) 25 | public void testLogMessage() { 26 | logMessage(Collections.singletonMap("key", "value")); 27 | } 28 | 29 | @Test(groups = { "unit" }) 30 | public void testLogWithFormat() { 31 | logWithFormat("msg %s %s %s %s", 1, 2.2, "3", new Object()); 32 | } 33 | 34 | @Test(groups = { "unit" }) 35 | public void testLogWithFunction() { 36 | logWithFunction(() -> Collections.singleton(1)); 37 | } 38 | 39 | @Test(groups = { "unit" }) 40 | public void testLogThrowable() { 41 | logThrowable("msg", new Exception("test exception")); 42 | } 43 | 44 | @Test(groups = { "unit" }) 45 | public void testLogWithFormatAndThrowable() { 46 | logWithFormatAndThrowable("msg %s %s %s %s", 1, 2.2, "3", new Object(), new Exception("test exception")); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/java/com/clickhouse/logging/Slf4jLoggerTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.logging; 2 | 3 | import java.util.Collections; 4 | import org.testng.annotations.Test; 5 | 6 | public class Slf4jLoggerTest extends LoggerTest { 7 | private final Slf4jLoggerFactory factory = new Slf4jLoggerFactory(); 8 | 9 | @Override 10 | protected Logger getLogger(Class clazz) { 11 | return factory.get(clazz); 12 | } 13 | 14 | @Override 15 | protected Logger getLogger(String name) { 16 | return factory.get(name); 17 | } 18 | 19 | @Test(groups = { "unit" }) 20 | public void testInstantiation() { 21 | checkInstance(Slf4jLogger.class); 22 | } 23 | 24 | @Test(groups = { "unit" }) 25 | public void testLogMessage() { 26 | logMessage(Collections.singletonMap("key", "value")); 27 | } 28 | 29 | @Test(groups = { "unit" }) 30 | public void testLogWithFormat() { 31 | logWithFormat("msg %s %s %s %s", 1, 2.2, "3", new Object()); 32 | } 33 | 34 | @Test(groups = { "unit" }) 35 | public void testLogWithFunction() { 36 | logWithFunction(() -> Collections.singleton(2L)); 37 | } 38 | 39 | @Test(groups = { "unit" }) 40 | public void testLogThrowable() { 41 | logThrowable("msg", new Exception("test exception")); 42 | } 43 | 44 | @Test(groups = { "unit" }) 45 | public void testLogWithFormatAndThrowable() { 46 | logWithFormatAndThrowable("msg %s %s %s %s", 1, 2.2, "3", new Object(), new Exception("test exception")); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /clickhouse-data/src/test/resources/META-INF/services/com.clickhouse.data.TestServiceInterface: -------------------------------------------------------------------------------- 1 | com.clickhouse.data.TestServiceImplementation -------------------------------------------------------------------------------- /clickhouse-data/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | org.slf4j.simpleLogger.log.com.clickhouse.data=info 3 | org.slf4j.simpleLogger.showDateTime=true 4 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z 5 | org.slf4j.simpleLogger.showThreadName=true 6 | org.slf4j.simpleLogger.showLogName=true 7 | org.slf4j.simpleLogger.showShortLogName=true 8 | -------------------------------------------------------------------------------- /clickhouse-http-client/src/main/java/com/clickhouse/client/http/config/HttpConnectionProvider.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.http.config; 2 | 3 | @Deprecated 4 | public enum HttpConnectionProvider { 5 | HTTP_CLIENT, 6 | HTTP_URL_CONNECTION, 7 | APACHE_HTTP_CLIENT 8 | } 9 | -------------------------------------------------------------------------------- /clickhouse-http-client/src/main/java11/module-info.java: -------------------------------------------------------------------------------- 1 | module com.clickhouse.client.http { 2 | exports com.clickhouse.client.http; 3 | exports com.clickhouse.client.http.config; 4 | 5 | provides com.clickhouse.client.ClickHouseClient with com.clickhouse.client.http.ClickHouseHttpClient; 6 | 7 | requires java.net.http; 8 | 9 | requires transitive com.clickhouse.client; 10 | } 11 | -------------------------------------------------------------------------------- /clickhouse-http-client/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | module com.clickhouse.client.http { 2 | exports com.clickhouse.client.http; 3 | exports com.clickhouse.client.http.config; 4 | 5 | provides com.clickhouse.client.ClickHouseClient with com.clickhouse.client.http.ClickHouseHttpClient; 6 | 7 | requires transitive com.clickhouse.client; 8 | } 9 | -------------------------------------------------------------------------------- /clickhouse-http-client/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-http-client/native-image.properties: -------------------------------------------------------------------------------- 1 | Args = --enable-url-protocols=http,https 2 | -------------------------------------------------------------------------------- /clickhouse-http-client/src/main/resources/META-INF/services/com.clickhouse.client.ClickHouseClient: -------------------------------------------------------------------------------- 1 | com.clickhouse.client.http.ClickHouseHttpClient 2 | -------------------------------------------------------------------------------- /clickhouse-http-client/src/test/java/com/clickhouse/client/http/DefaultHttpConnectionTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.http; 2 | 3 | import com.clickhouse.client.BaseIntegrationTest; 4 | import com.clickhouse.client.ClickHouseClient; 5 | import com.clickhouse.client.ClickHouseNode; 6 | import com.clickhouse.client.ClickHouseProtocol; 7 | import com.clickhouse.client.ClickHouseRequest; 8 | 9 | import java.io.IOException; 10 | 11 | import org.testng.Assert; 12 | import org.testng.annotations.Test; 13 | 14 | public class DefaultHttpConnectionTest extends BaseIntegrationTest { 15 | @Test(groups = { "integration" }) 16 | public void testConnectionReuse() throws IOException { 17 | ClickHouseNode server = getServer(ClickHouseProtocol.HTTP); 18 | 19 | try (ClickHouseClient client = ClickHouseClient.newInstance()) { 20 | ClickHouseRequest req = client.read(server); 21 | 22 | ClickHouseHttpConnection conn = ClickHouseHttpConnectionFactory.createConnection(server, req, null); 23 | Assert.assertNotNull(conn); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /clickhouse-http-client/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | org.slf4j.simpleLogger.log.com.clickhouse.client=debug 3 | org.slf4j.simpleLogger.showDateTime=true 4 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z 5 | org.slf4j.simpleLogger.showThreadName=true 6 | org.slf4j.simpleLogger.showLogName=true 7 | org.slf4j.simpleLogger.showShortLogName=true 8 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseStatement.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc; 2 | 3 | import java.io.OutputStream; 4 | import java.sql.SQLException; 5 | import java.sql.Statement; 6 | 7 | import com.clickhouse.client.ClickHouseConfig; 8 | import com.clickhouse.client.ClickHouseRequest; 9 | import com.clickhouse.client.ClickHouseRequest.Mutation; 10 | 11 | @Deprecated 12 | public interface ClickHouseStatement extends Statement { 13 | @Override 14 | ClickHouseConnection getConnection() throws SQLException; 15 | 16 | ClickHouseConfig getConfig(); 17 | 18 | /** 19 | * Gets mirrored output stream. 20 | * 21 | * @return mirrored output stream, could be null 22 | */ 23 | OutputStream getMirroredOutput(); 24 | 25 | /** 26 | * Sets mirrored output stream, which will be later used for dumping all 27 | * {@link java.sql.ResultSet} generated by this statement, via 28 | * {@link com.clickhouse.data.ClickHouseInputStream#setCopyToTarget(OutputStream)}. 29 | * 30 | * @param out mirrored output stream, could be null 31 | */ 32 | void setMirroredOutput(OutputStream out); 33 | 34 | int getNullAsDefault(); 35 | 36 | void setNullAsDefault(int level); 37 | 38 | ClickHouseRequest getRequest(); 39 | 40 | default Mutation write() { 41 | return getRequest().write(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseStruct.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc; 2 | 3 | import java.sql.SQLException; 4 | import java.sql.Struct; 5 | import java.util.Map; 6 | 7 | import com.clickhouse.data.ClickHouseChecker; 8 | 9 | @Deprecated 10 | public class ClickHouseStruct implements Struct { 11 | private final String typeName; 12 | private final Object[] values; 13 | 14 | protected ClickHouseStruct(String typeName, Object[] values) { 15 | this.typeName = ClickHouseChecker.nonNull(typeName, "SQLTypeName"); 16 | this.values = ClickHouseChecker.nonNull(values, "values"); 17 | } 18 | 19 | @Override 20 | public String getSQLTypeName() throws SQLException { 21 | return typeName; 22 | } 23 | 24 | @Override 25 | public Object[] getAttributes() throws SQLException { 26 | return values; 27 | } 28 | 29 | @Override 30 | public Object[] getAttributes(Map> map) throws SQLException { 31 | return getAttributes(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/JdbcWrapper.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc; 2 | 3 | import java.sql.SQLException; 4 | 5 | @Deprecated 6 | public abstract class JdbcWrapper { 7 | public T unwrap(Class iface) throws SQLException { 8 | if (iface.isAssignableFrom(getClass())) { 9 | return iface.cast(this); 10 | } 11 | 12 | throw SqlExceptionUtils.unsupportedError("Cannot unwrap to " + iface.getName()); 13 | } 14 | 15 | public boolean isWrapperFor(Class iface) throws SQLException { 16 | return iface.isAssignableFrom(getClass()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/JdbcSavepoint.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc.internal; 2 | 3 | import java.sql.SQLException; 4 | import java.sql.Savepoint; 5 | 6 | import com.clickhouse.jdbc.SqlExceptionUtils; 7 | 8 | @Deprecated 9 | public class JdbcSavepoint implements Savepoint { 10 | final int id; 11 | final String name; 12 | 13 | JdbcSavepoint(int id, String name) { 14 | this.id = id; 15 | this.name = name; 16 | } 17 | 18 | @Override 19 | public int getSavepointId() throws SQLException { 20 | if (name != null) { 21 | throw SqlExceptionUtils 22 | .clientError("Cannot get ID from a named savepoint, please use getSavepointName() instead"); 23 | } 24 | 25 | return id; 26 | } 27 | 28 | @Override 29 | public String getSavepointName() throws SQLException { 30 | if (name == null) { 31 | throw SqlExceptionUtils 32 | .clientError("Cannot get name from an un-named savepoint, please use getSavepointId() instead"); 33 | } 34 | 35 | return name; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return new StringBuilder().append("JdbcSavepoint [id=").append(id).append(", name=").append(name) 41 | .append(']').toString(); 42 | } 43 | } -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/parser/LanguageType.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc.parser; 2 | 3 | @Deprecated 4 | public enum LanguageType { 5 | UNKNOWN, // unknown language 6 | DCL, // data control language 7 | DDL, // data definition language 8 | DML, // data manipulation language 9 | TCL // transaction control language 10 | } 11 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/parser/OperationType.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc.parser; 2 | 3 | @Deprecated 4 | public enum OperationType { 5 | UNKNOWN, READ, WRITE 6 | } 7 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java11/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse module. 3 | */ 4 | module com.clickhouse.jdbc { 5 | exports com.clickhouse.jdbc; 6 | 7 | requires java.sql; 8 | 9 | requires transitive com.clickhouse.client; 10 | // requires transitive com.google.gson; 11 | // requires transitive org.lz4.java; 12 | 13 | uses com.clickhouse.client.ClickHouseClient; 14 | uses com.clickhouse.client.ClickHouseDnsResolver; 15 | uses com.clickhouse.client.ClickHouseSslContextProvider; 16 | uses com.clickhouse.data.ClickHouseDataStreamFactory; 17 | uses com.clickhouse.logging.LoggerFactory; 18 | } 19 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse module. 3 | */ 4 | module com.clickhouse.jdbc { 5 | exports com.clickhouse.jdbc; 6 | 7 | requires java.sql; 8 | 9 | requires transitive com.clickhouse.client; 10 | // requires transitive com.google.gson; 11 | // requires transitive org.lz4.java; 12 | 13 | uses com.clickhouse.client.ClickHouseClient; 14 | uses com.clickhouse.client.ClickHouseDnsResolver; 15 | uses com.clickhouse.client.ClickHouseSslContextProvider; 16 | uses com.clickhouse.data.ClickHouseDataStreamFactory; 17 | uses com.clickhouse.logging.LoggerFactory; 18 | } 19 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-jdbc/native-image.properties: -------------------------------------------------------------------------------- 1 | Args = -H:ReflectionConfigurationResources=${.}/reflect-config.json 2 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-jdbc/reflect-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4HCJNICompressor", 4 | "fields": [{ "name": "INSTANCE" }], 5 | "methods": [{ "name": "", "parameterTypes": ["int"] }] 6 | }, 7 | { 8 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4HCJavaUnsafeCompressor", 9 | "fields": [{ "name": "INSTANCE" }], 10 | "methods": [{ "name": "", "parameterTypes": ["int"] }] 11 | }, 12 | { 13 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JNICompressor", 14 | "fields": [{ "name": "INSTANCE" }] 15 | }, 16 | { 17 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JNIFastDecompressor", 18 | "fields": [{ "name": "INSTANCE" }] 19 | }, 20 | { 21 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JNISafeDecompressor", 22 | "fields": [{ "name": "INSTANCE" }] 23 | }, 24 | { 25 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JavaUnsafeCompressor", 26 | "fields": [{ "name": "INSTANCE" }] 27 | }, 28 | { 29 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JavaUnsafeFastDecompressor", 30 | "fields": [{ "name": "INSTANCE" }] 31 | }, 32 | { 33 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JavaUnsafeSafeDecompressor", 34 | "fields": [{ "name": "INSTANCE" }] 35 | } 36 | ] 37 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/resources/META-INF/services/java.sql.Driver: -------------------------------------------------------------------------------- 1 | com.clickhouse.jdbc.ClickHouseDriver 2 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/main/resources/clickhouse-jdbc-version.properties: -------------------------------------------------------------------------------- 1 | version=${revision} 2 | build.date=${build_timestamp} -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/perf/README.md: -------------------------------------------------------------------------------- 1 | # Performance Testing using JMH for JDBC driver 2 | Testing of Insert, Select & comparing the performance of JDBC V1 & JDBC V2 3 | Insert testing 4 | - batch sizes [100, 1000, 10000, 100000] 5 | - data types [int8, int16, int32, int64, float32, float64, string, boolean] (Will be extended to other data types as well) 6 | 7 | Note: string payload size is adjustable ["1024", "2048", "4096", "8192" ] 8 | 9 | Select testing query `"SELECT * FROM %s LIMIT %d"` 10 | - limit is adjustable currently use 100 11 | - retrieval of different data types [int8, int16, int32, int64, float32, float64, string, boolean] (Will be extended to other data types as well) 12 | - separated test for connection part and connection with deserialization part 13 | 14 | # how to run 15 | mvn clean package -DskipTests=true -P performance-testing-jdbc 16 | 17 | # output file 18 | The benchmark generate the output file in jmh-jdbc-results.json 19 | Use https://jmh.morethan.io/ to visualize the results 20 | 21 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/perf/com/clickhouse/jdbc/perf/JDBCBenchmarkRunner.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc.perf; 2 | 3 | import org.openjdk.jmh.annotations.Mode; 4 | import org.openjdk.jmh.profile.GCProfiler; 5 | import org.openjdk.jmh.profile.MemPoolProfiler; 6 | import org.openjdk.jmh.results.format.ResultFormatType; 7 | import org.openjdk.jmh.runner.Runner; 8 | import org.openjdk.jmh.runner.options.Options; 9 | import org.openjdk.jmh.runner.options.OptionsBuilder; 10 | import org.openjdk.jmh.runner.options.TimeValue; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | import java.util.concurrent.TimeUnit; 15 | 16 | public class JDBCBenchmarkRunner { 17 | private static final Logger LOGGER = LoggerFactory.getLogger(JDBCBenchmarkRunner.class); 18 | 19 | public static void main(String[] args) throws Exception { 20 | LOGGER.info("Starting Benchmarks"); 21 | Options opt = new OptionsBuilder() 22 | .include(JDBCSelectBenchmark.class.getSimpleName()) 23 | .include(JDBCInsertBenchmark.class.getSimpleName()) 24 | .forks(1) 25 | .mode(Mode.AverageTime) 26 | .timeUnit(TimeUnit.MILLISECONDS) 27 | .threads(1) 28 | .addProfiler(GCProfiler.class) 29 | .addProfiler(MemPoolProfiler.class) 30 | .warmupIterations(1) 31 | .warmupTime(TimeValue.seconds(5)) 32 | .measurementIterations(1) 33 | .measurementTime(TimeValue.seconds(5)) 34 | .resultFormat(ResultFormatType.JSON) 35 | .result("jmh-jdbc-results.json") 36 | .build(); 37 | new Runner(opt).run(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/resources/data_samples/test_sample.orc.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/clickhouse-jdbc/src/test/resources/data_samples/test_sample.orc.gz -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/resources/data_samples/test_sample.parquet.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/clickhouse-jdbc/src/test/resources/data_samples/test_sample.parquet.gz -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | org.slf4j.simpleLogger.log.com.clickhouse.jdbc=debug 3 | org.slf4j.simpleLogger.showDateTime=true 4 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z 5 | org.slf4j.simpleLogger.showThreadName=true 6 | org.slf4j.simpleLogger.showLogName=true 7 | org.slf4j.simpleLogger.showShortLogName=true 8 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/resources/sqls/issue-441_with-totals.sql: -------------------------------------------------------------------------------- 1 | WITH 2 AS factor 2 | SELECT 3 | number % 2 AS odd_even, 4 | count(*) AS count, 5 | sum(factor * number) AS output 6 | FROM 7 | ( 8 | SELECT number 9 | FROM system.numbers 10 | LIMIT 100 11 | ) 12 | GROUP BY number % 2 13 | WITH TOTALS -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/resources/sqls/issue-555_custom-format.sql: -------------------------------------------------------------------------------- 1 | select 2 | JSONExtractRaw(abcedfg.fields, 'someDateField___e') as abc_someDateField___e, 3 | some_word as sw_someWord, 4 | JSONExtractString(abcedfg.fields, 'field') as abc_field, 5 | some_more_words as sw_moreWords , 6 | last_word as sw_lastWord, 7 | JSONExtractInt(abcedfg.fields, 'countOfWords') as abc_countOfWords, 8 | abcedfg.id as abc_id, 9 | JSONExtractString(abcedfg.fields, 'somePlace') as abc_somePlace, 10 | JSONExtractString(abcedfg.fields, 'place') as abc_place, 11 | JSONExtractInt(abcedfg.fields, 'countOfPlaces') as abc_countOfPlaces, 12 | abcedfg.name as abc_name, 13 | (some_more_words * 100 / (even_more_words * (? / 28))) - 100 as sw_wordsPercentChange, 14 | some_unique_words as sw_uniqueWords 15 | from ( 16 | select 17 | abcedfg_id, 18 | sum(if(toDate(sample_date) >= toDate(?, 'UTC'), 1, 0)) some_more_words, 19 | count(distinct if(toDate(sample_date) >= toDate(?, 'UTC'), wrd.word_id, null)) some_unique_words, 20 | sum(if(toDate(sample_date) < toDate(?, 'UTC'), 1, 0)) even_more_words, 21 | min(toDate(sample_date, 'UTC')) some_word, 22 | max(toDate(sample_date, 'UTC')) last_word 23 | from a1234_test.sample wrd 24 | join a1234_test.abcedfg_list_item itm on itm.abcedfg_id = wrd.abcedfg_id 25 | where toDate(sample_date, 'UTC') between 26 | addDays(toDate(?, 'UTC'), -28) 27 | and toDate(?, 'UTC') 28 | and wrd.sample_type_id IN (?) 29 | and itm.abcedfg_list_id IN (?) 30 | and 1 31 | group by abcedfg_id 32 | ) as wrd 33 | join a1234_test.abcedfg abc on abc.id = wrd.abcedfg_id 34 | order by sw_moreWords desc 35 | limit ? offset ? 36 | FORMAT CSVWithNames 37 | -------------------------------------------------------------------------------- /clickhouse-jdbc/src/test/resources/sqls/with-clause.sql: -------------------------------------------------------------------------------- 1 | WITH ( 2 | ( 3 | SELECT query_start_time_microseconds 4 | FROM system.query_log 5 | WHERE current_database = currentDatabase() 6 | ORDER BY query_start_time DESC 7 | LIMIT 1 8 | ) AS time_with_microseconds, 9 | ( 10 | SELECT query_start_time 11 | FROM system.query_log 12 | WHERE current_database = currentDatabase() 13 | ORDER BY query_start_time DESC 14 | LIMIT 1 15 | ) AS t) 16 | SELECT if(dateDiff('second', toDateTime(time_with_microseconds), toDateTime(t)) = 0, 'ok', 'fail') -------------------------------------------------------------------------------- /clickhouse-r2dbc/README.md: -------------------------------------------------------------------------------- 1 | # ClickHouse R2DBC Driver 2 | 3 | [R2DBC](https://r2dbc.io/) wrapper of async [Java client](/ClickHouse/clickhouse-java/clickhouse-client) for ClickHouse. 4 | 5 | ## Documentation 6 | See the [ClickHouse website](https://clickhouse.com/docs/en/integrations/language-clients/java/r2dbc) for the full documentation entry. 7 | 8 | ## Examples 9 | For more example please check [here](https://github.com/ClickHouse/clickhouse-java/tree/main/examples/r2dbc). 10 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/ClickHouseBatch.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc; 2 | 3 | import com.clickhouse.client.ClickHouseRequest; 4 | import com.clickhouse.data.ClickHouseFormat; 5 | import io.r2dbc.spi.Batch; 6 | import io.r2dbc.spi.Result; 7 | import org.reactivestreams.Publisher; 8 | import reactor.core.publisher.Flux; 9 | import reactor.core.publisher.Mono; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class ClickHouseBatch implements Batch { 15 | 16 | private static final ClickHouseFormat PREFERRED_FORMAT = ClickHouseFormat.TabSeparatedWithNamesAndTypes; 17 | private ClickHouseRequest request; 18 | final List sqlList; 19 | 20 | public ClickHouseBatch(ClickHouseRequest request) { 21 | this.request = request; 22 | this.sqlList = new ArrayList<>(); 23 | } 24 | 25 | @Override 26 | public Batch add(String sql) { 27 | sqlList.add(sql); 28 | return this; 29 | } 30 | 31 | @Override 32 | public Publisher execute() { 33 | return Flux.fromStream(sqlList.stream().map(sql -> { 34 | request.query(sql).format(PREFERRED_FORMAT); 35 | return Mono.fromFuture(request::execute); })) 36 | .flatMap(Mono::flux) 37 | .map(ClickHouseResult::new); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/ClickHouseColumnMetadata.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc; 2 | 3 | import com.clickhouse.data.ClickHouseColumn; 4 | import com.clickhouse.r2dbc.types.ClickHouseDataTypeWrapper; 5 | import io.r2dbc.spi.ColumnMetadata; 6 | import io.r2dbc.spi.Type; 7 | 8 | public class ClickHouseColumnMetadata implements ColumnMetadata { 9 | 10 | final Type type; 11 | final String name; 12 | 13 | ClickHouseColumnMetadata(ClickHouseColumn col) { 14 | this.name = col.getColumnName(); // TODO :check alias handling. 15 | this.type = ClickHouseDataTypeWrapper.of(col.getDataType()); 16 | } 17 | 18 | @Override 19 | public Type getType() { 20 | return type; 21 | } 22 | 23 | @Override 24 | public String getName() { 25 | return name; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/ClickHousePair.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map.Entry; 5 | 6 | /** 7 | * Immutable pair with two values: left and right. 8 | */ 9 | public class ClickHousePair implements Entry, Serializable { 10 | public static final ClickHousePair EMPTY = new ClickHousePair<>(null, null); 11 | 12 | @SuppressWarnings("unchecked") 13 | public static final ClickHousePair of(L left, R right) { 14 | if (left == null && right == null) { 15 | return (ClickHousePair) EMPTY; 16 | } 17 | 18 | return new ClickHousePair<>(left, right); 19 | } 20 | 21 | private final L left; 22 | private final R right; 23 | 24 | public L getLeft() { 25 | return left; 26 | } 27 | 28 | public R getRight() { 29 | return right; 30 | } 31 | 32 | protected ClickHousePair(L left, R right) { 33 | this.left = left; 34 | this.right = right; 35 | } 36 | 37 | @Override 38 | public L getKey() { 39 | return left; 40 | } 41 | 42 | @Override 43 | public R getValue() { 44 | return right; 45 | } 46 | 47 | @Override 48 | public R setValue(R value) { 49 | throw new IllegalStateException("Cannot modify value"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/ClickHouseRowMetadata.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc; 2 | 3 | import io.r2dbc.spi.ColumnMetadata; 4 | import io.r2dbc.spi.RowMetadata; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | import java.util.LinkedHashMap; 10 | import java.util.List; 11 | 12 | public class ClickHouseRowMetadata implements RowMetadata { 13 | 14 | LinkedHashMap columnNameMetadataMap; 15 | 16 | ClickHouseRowMetadata(LinkedHashMap columnNameMetadataMap) { 17 | this.columnNameMetadataMap = columnNameMetadataMap; 18 | } 19 | 20 | @Override 21 | public ColumnMetadata getColumnMetadata(int i) { 22 | if (i > columnNameMetadataMap.size()) 23 | throw new IllegalArgumentException("Given index is greater than size column metadata array."); 24 | return columnNameMetadataMap.entrySet().stream().skip(i - 1L).findFirst().get().getValue(); // NOSONAR 25 | } 26 | 27 | @Override 28 | public ColumnMetadata getColumnMetadata(String columnName) { 29 | return columnNameMetadataMap.get(columnName); 30 | } 31 | 32 | @Override 33 | public List getColumnMetadatas() { 34 | return Collections.unmodifiableList(new ArrayList<>(columnNameMetadataMap.values())); 35 | } 36 | 37 | // deprecated method 38 | public Collection getColumnNames() { 39 | return Collections.unmodifiableCollection(new ArrayList<>(columnNameMetadataMap.keySet())); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/ClickHouseStatementBinding.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | class ClickHouseStatementBinding { 7 | public static final String NOT_ALL_PARAMETERS_ARE_SET = "Not all parameters are set."; 8 | List bindingList; 9 | Binding current; 10 | int size; 11 | 12 | ClickHouseStatementBinding(int size) { 13 | this.size = size; 14 | current = new Binding(size); 15 | bindingList = new ArrayList<>(); 16 | } 17 | 18 | void addBinding(int index, Object value) { 19 | current.setParam(index, value); 20 | } 21 | 22 | void add() { 23 | if (current.isCompleted()) { 24 | bindingList.add(current); 25 | current = new Binding(size); 26 | } 27 | 28 | } 29 | 30 | List getBoundList() { 31 | List bindingList = (this.bindingList == null) ? new ArrayList<>() : this.bindingList; 32 | if (current.values.length > 0 && current.isCompleted()) 33 | bindingList.add(current); 34 | return bindingList; 35 | } 36 | 37 | public static class Binding { 38 | 39 | Object[] values; 40 | 41 | private Binding(int size) { 42 | values = new Object[size]; 43 | } 44 | 45 | private void setParam(int index, Object value) { 46 | values[index] = value; 47 | } 48 | 49 | private boolean isCompleted(){ 50 | for (Object value: values) { 51 | if (value == null) throw new IllegalStateException(NOT_ALL_PARAMETERS_ARE_SET); 52 | } 53 | return true; 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/connection/ClickHouseConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.connection; 2 | 3 | import java.util.function.Function; 4 | 5 | import com.clickhouse.client.ClickHouseNode; 6 | import com.clickhouse.client.ClickHouseNodeSelector; 7 | import io.r2dbc.spi.Connection; 8 | import io.r2dbc.spi.ConnectionFactory; 9 | import io.r2dbc.spi.ConnectionFactoryMetadata; 10 | import reactor.core.publisher.Mono; 11 | 12 | public class ClickHouseConnectionFactory implements ConnectionFactory { 13 | private final Function nodes; 14 | 15 | ClickHouseConnectionFactory(Function nodes) { 16 | this.nodes = nodes; 17 | } 18 | 19 | @Override 20 | public Mono create() { 21 | return Mono.defer(() -> Mono.just(new ClickHouseConnection(nodes))); 22 | } 23 | 24 | @Override 25 | public ConnectionFactoryMetadata getMetadata() { 26 | return ClickHouseConnectionFactoryMetadata.INSTANCE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/connection/ClickHouseConnectionFactoryMetadata.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.connection; 2 | 3 | import io.r2dbc.spi.ConnectionFactoryMetadata; 4 | 5 | public class ClickHouseConnectionFactoryMetadata implements ConnectionFactoryMetadata { 6 | 7 | static final ClickHouseConnectionFactoryMetadata INSTANCE = new ClickHouseConnectionFactoryMetadata(); 8 | 9 | @Override 10 | public String getName() { 11 | return "ClickHouse"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java/com/clickhouse/r2dbc/types/ClickHouseDataTypeWrapper.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.types; 2 | 3 | import com.clickhouse.data.ClickHouseDataType; 4 | import io.r2dbc.spi.Type; 5 | 6 | 7 | public class ClickHouseDataTypeWrapper implements Type { 8 | final ClickHouseDataType dType; 9 | 10 | private ClickHouseDataTypeWrapper(ClickHouseDataType dType){ 11 | this.dType = dType; 12 | } 13 | 14 | public static ClickHouseDataTypeWrapper of(ClickHouseDataType dType) { 15 | return new ClickHouseDataTypeWrapper(dType); 16 | } 17 | 18 | 19 | @Override 20 | public Class getJavaType() { 21 | return dType.getObjectClass(); 22 | } 23 | 24 | @Override 25 | public String getName() { 26 | return dType.name(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java11/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse.r2dbc module. 3 | */ 4 | module com.clickhouse.r2dbc { 5 | exports com.clickhouse.r2dbc; 6 | 7 | requires transitive com.clickhouse.client; 8 | requires transitive r2dbc.spi; 9 | requires transitive reactor.core; 10 | requires transitive org.lz4.java; 11 | 12 | uses com.clickhouse.client.ClickHouseClient; 13 | uses com.clickhouse.client.ClickHouseDnsResolver; 14 | uses com.clickhouse.client.ClickHouseSslContextProvider; 15 | uses com.clickhouse.data.ClickHouseDataStreamFactory; 16 | uses com.clickhouse.logging.LoggerFactory; 17 | } 18 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse.r2dbc module. 3 | */ 4 | module com.clickhouse.r2dbc { 5 | exports com.clickhouse.r2dbc; 6 | 7 | requires transitive com.clickhouse.client; 8 | requires transitive r2dbc.spi; 9 | requires transitive reactor.core; 10 | requires transitive org.lz4.java; 11 | 12 | uses com.clickhouse.client.ClickHouseClient; 13 | uses com.clickhouse.client.ClickHouseDnsResolver; 14 | uses com.clickhouse.client.ClickHouseSslContextProvider; 15 | uses com.clickhouse.data.ClickHouseDataStreamFactory; 16 | uses com.clickhouse.logging.LoggerFactory; 17 | } 18 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/main/resources/META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider: -------------------------------------------------------------------------------- 1 | com.clickhouse.r2dbc.connection.ClickHouseConnectionFactoryProvider 2 | -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/test/java/com/clickhouse/r2dbc/connection/ClickHouseConnectionTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.connection; 2 | 3 | import java.util.concurrent.atomic.AtomicReference; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import com.clickhouse.r2dbc.BaseR2dbcTest; 9 | 10 | import io.r2dbc.spi.ConnectionFactory; 11 | import reactor.core.publisher.Mono; 12 | 13 | public class ClickHouseConnectionTest extends BaseR2dbcTest { 14 | protected void executeQuery(String sql, String expectedStringResults, String customConnStr) { 15 | ConnectionFactory connectionFactory = getConnectionFactory(DEFAULT_PROTOCOL, EXTRA_PARAM, customConnStr); 16 | 17 | AtomicReference error = new AtomicReference<>(); 18 | StringBuilder builder = new StringBuilder(64); 19 | Mono.from(connectionFactory.create()) 20 | .flatMapMany(connection -> connection.createStatement(sql).execute()) 21 | .flatMap(result -> result.map((row, rowMetadata) -> row.get(0))) 22 | .doOnNext(result -> builder.append(result)) 23 | .doOnError(error::set) 24 | .then() 25 | .block(); 26 | 27 | Assert.assertNull("Should not run into error", error.get()); 28 | Assert.assertEquals(expectedStringResults, builder.toString()); 29 | } 30 | 31 | // @Test 32 | public void testQuery() throws Exception { 33 | String sql = "SELECT * FROM numbers(10)"; 34 | String expected = "0123456789"; 35 | executeQuery(sql, expected, null); 36 | executeQuery(sql, expected, "format=CSV"); 37 | executeQuery(sql, expected, "format=CSV&max_result_rows=11"); 38 | } 39 | } -------------------------------------------------------------------------------- /clickhouse-r2dbc/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | org.slf4j.simpleLogger.log.com.clickhouse.client=debug 3 | org.slf4j.simpleLogger.showDateTime=true 4 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z 5 | org.slf4j.simpleLogger.showThreadName=true 6 | org.slf4j.simpleLogger.showLogName=true 7 | org.slf4j.simpleLogger.showShortLogName=true 8 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/ClientException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | public class ClientException extends RuntimeException { 4 | 5 | public ClientException(String message) { 6 | super(message); 7 | } 8 | 9 | public ClientException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/ClientFaultCause.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | public enum ClientFaultCause { 4 | 5 | None, 6 | 7 | NoHttpResponse, 8 | ConnectTimeout, 9 | ConnectionRequestTimeout, 10 | SocketTimeout, 11 | } 12 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/ClientMisconfigurationException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | /** 4 | * Represents errors caused by a client misconfiguration. 5 | */ 6 | public class ClientMisconfigurationException extends ClientException { 7 | public ClientMisconfigurationException(String message) { 8 | super(message); 9 | } 10 | 11 | public ClientMisconfigurationException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/ConnectionInitiationException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | public class ConnectionInitiationException extends ClientException { 4 | 5 | public ConnectionInitiationException(String message) { 6 | super(message); 7 | } 8 | 9 | public ConnectionInitiationException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/ConnectionReuseStrategy.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | public enum ConnectionReuseStrategy { 4 | 5 | /** 6 | * Reuse recently freed connection and returned to a pool 7 | */ 8 | LIFO, 9 | 10 | /** 11 | * Reuse mostly all connections 12 | */ 13 | FIFO 14 | ; 15 | } 16 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/DataStreamWriter.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | public interface DataStreamWriter { 7 | 8 | /** 9 | * Called by client when output stream is ready for user data. 10 | * This method is called once per operation, so all data should be written while the call. 11 | * Output stream will be closed by client. 12 | * When client compression is enabled, then output stream will be a compressing one. 13 | * If {@link ClientConfigProperties#APP_COMPRESSED_DATA} is set for an operation, 14 | * then {@param out} will be raw IO stream without compression. 15 | * @param out - output stream 16 | * @throws IOException - when any IO exceptions happens. 17 | */ 18 | void onOutput(OutputStream out) throws IOException; 19 | 20 | /** 21 | * Is called when client is going to perform a retry. 22 | * It is optional to implement this method because most cases there is nothing to reset. 23 | * Useful to reset wrapped stream or throw exception to indicate that retry is not supported for a data source. 24 | * @throws IOException - when any IO exception happens. 25 | */ 26 | default void onRetry() throws IOException {} 27 | } 28 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/DataTypeUtils.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | import java.time.format.DateTimeFormatter; 4 | 5 | public class DataTypeUtils { 6 | 7 | /** 8 | * Formatter for the DateTime type. 9 | */ 10 | public static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 11 | 12 | /** 13 | * Formatter for the Date type. 14 | */ 15 | public static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 16 | 17 | /** 18 | * Formatter for the DateTime type with nanoseconds. 19 | */ 20 | public static DateTimeFormatter DATETIME_WITH_NANOS_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.nnnnnnnnn"); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/ServerException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | public class ServerException extends RuntimeException { 4 | 5 | public static final int CODE_UNKNOWN = 0; 6 | 7 | public static final int TABLE_NOT_FOUND = 60; 8 | 9 | private final int code; 10 | 11 | private final int transportProtocolCode; 12 | 13 | public ServerException(int code, String message) { 14 | this(code, message, 500); 15 | } 16 | 17 | public ServerException(int code, String message, int transportProtocolCode) { 18 | super(message); 19 | this.code = code; 20 | this.transportProtocolCode = transportProtocolCode; 21 | } 22 | 23 | /** 24 | * Returns CH server error code. May return 0 if code is unknown. 25 | * @return - error code from server response 26 | */ 27 | public int getCode() { 28 | return code; 29 | } 30 | 31 | /** 32 | * Returns error code of underlying transport protocol. For example, HTTP status. 33 | * By default, will return {@code 500 } what is derived from HTTP Server Internal Error. 34 | * 35 | * @return - transport status code 36 | */ 37 | public int getTransportProtocolCode() { 38 | return transportProtocolCode; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/command/CommandSettings.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.command; 2 | 3 | import com.clickhouse.client.api.query.QuerySettings; 4 | 5 | public class CommandSettings extends QuerySettings { 6 | } 7 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/enums/Protocol.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.enums; 2 | 3 | public enum Protocol { 4 | HTTP 5 | } 6 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/enums/ProxyType.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.enums; 2 | 3 | public enum ProxyType { 4 | //DIRECT, 5 | HTTP, 6 | SOCKS; 7 | } 8 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/internal/BasicObjectsPool.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | import java.util.Deque; 4 | 5 | 6 | /** 7 | * Objects pool. 8 | * Can be used to reuse object to reduce GC pressure. 9 | * Thread-safety is not guaranteed. Depends on deque implementation that is 10 | * passed to the constructor. 11 | * @param - type of stored objects 12 | */ 13 | public abstract class BasicObjectsPool { 14 | 15 | private Deque objects; 16 | 17 | /** 18 | * Creates an empty pool. 19 | * @param objects object queue 20 | */ 21 | BasicObjectsPool(Deque objects) { 22 | this(objects, 0); 23 | } 24 | 25 | /** 26 | * Creates a pool and pre-populates it with a number of objects equal to the size parameter. 27 | * @param objects object queue 28 | * @param size initial size of the object queue 29 | */ 30 | public BasicObjectsPool(Deque objects, int size) { 31 | this.objects = objects; 32 | for (int i = 0; i < size; i++) { 33 | this.objects.add(create()); 34 | } 35 | } 36 | 37 | public T lease() { 38 | T obj = objects.poll(); 39 | return obj != null ? obj : create(); 40 | } 41 | 42 | public void release(T obj) { 43 | objects.addFirst(obj); 44 | } 45 | 46 | protected abstract T create(); 47 | } 48 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/internal/CachingObjectsSupplier.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | import java.util.Deque; 4 | import java.util.Iterator; 5 | import java.util.function.Supplier; 6 | 7 | public abstract class CachingObjectsSupplier implements Supplier { 8 | 9 | private Iterator iterator; 10 | private Deque cache;; 11 | 12 | /** 13 | * Constructs caching object supplier that uses Deque as cache. Deque may be a thread safe implementation. 14 | * It will be filled with {@code preallocate} number of objects. 15 | * 16 | * @param cache 17 | * @param preallocate 18 | */ 19 | public CachingObjectsSupplier(Deque cache, int preallocate) { 20 | this.cache = cache; 21 | } 22 | 23 | @Override 24 | public T get() { 25 | T obj; 26 | if (iterator.hasNext()) { 27 | obj = iterator.next(); 28 | } else { 29 | obj = create(); 30 | cache.addFirst(obj); 31 | } 32 | 33 | return obj; 34 | } 35 | 36 | /** 37 | * Resets internal iterator to begin with the first object in the cache. 38 | */ 39 | public void reset() { 40 | iterator = cache.iterator(); 41 | } 42 | 43 | public abstract T create(); 44 | } 45 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/internal/ClientStatisticsHolder.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | import com.clickhouse.client.api.metrics.ClientMetrics; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class ClientStatisticsHolder { 9 | 10 | private final Map stopWatches = new HashMap<>(); 11 | 12 | public void start(ClientMetrics metric) { 13 | start(metric.getKey()); 14 | } 15 | 16 | public void start(String spanName) { 17 | stopWatches.computeIfAbsent(spanName, k -> new StopWatch()).start(); 18 | } 19 | 20 | public StopWatch stop(ClientMetrics metric) { 21 | return stop(metric.getKey()); 22 | } 23 | 24 | public StopWatch stop(String spanName) { 25 | StopWatch timer = stopWatches.computeIfAbsent(spanName, k -> new StopWatch()); 26 | timer.stop(); 27 | return timer; 28 | } 29 | 30 | public long getElapsedTime(String spanName) { 31 | StopWatch sw = stopWatches.get(spanName); 32 | return sw == null ? -1 : sw.getElapsedTime(); 33 | } 34 | 35 | public Map getStopWatches() { 36 | return stopWatches; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "ClientStatistics{" + 42 | "\"spans\"=" + stopWatches + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/internal/EnvUtils.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.net.InetAddress; 7 | import java.net.NetworkInterface; 8 | import java.util.Collections; 9 | 10 | /** 11 | * Environment utility class. 12 | */ 13 | public class EnvUtils { 14 | 15 | private static final Logger LOG = LoggerFactory.getLogger(EnvUtils.class); 16 | 17 | /** 18 | * Returns the local host name or IP address. Can be used to set {@code Referer} HTTP header. 19 | * If fails to find the local host name or address, returns an empty string. 20 | * @param returnAddress if true, return address; otherwise, return name 21 | * @return string representing the local host name or address 22 | */ 23 | public static String getLocalhostNameOrAddress(final boolean returnAddress) { 24 | try { 25 | 26 | for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) { 27 | for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) { 28 | if (inetAddress.isLoopbackAddress()) { 29 | continue; 30 | } 31 | if (returnAddress) { 32 | return inetAddress.getHostAddress(); 33 | } else { 34 | return inetAddress.getCanonicalHostName(); 35 | } 36 | } 37 | } 38 | } catch (Exception e) { 39 | LOG.error("Failed to get local host name or address", e); 40 | } 41 | return ""; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/internal/Gauge.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | import com.clickhouse.client.api.metrics.Metric; 4 | 5 | public class Gauge implements Metric { 6 | 7 | private volatile long value; 8 | 9 | public Gauge(long readRows) { 10 | this.value = readRows; 11 | } 12 | 13 | public void set(long value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public long getLong() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/internal/ServerSettings.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | 4 | /** 5 | * Incomplete list of server side settings. 6 | * This class is not intended to list all possible settings, but only those that are commonly used. 7 | * 8 | */ 9 | public final class ServerSettings { 10 | 11 | public static final String WAIT_END_OF_QUERY = "wait_end_of_query"; 12 | 13 | // -- Experimental features -- 14 | 15 | /** 16 | * Server will expect a string in JSON format and parse it into a JSON object. 17 | */ 18 | public static final String INPUT_FORMAT_BINARY_READ_JSON_AS_STRING = "input_format_binary_read_json_as_string"; 19 | 20 | /** 21 | * Server will return a JSON object as a string. 22 | */ 23 | public static final String OUTPUT_FORMAT_BINARY_WRITE_JSON_AS_STRING = "output_format_binary_write_json_as_string"; 24 | 25 | /** 26 | * Limit number of rows in a result set 27 | */ 28 | public static final String MAX_RESULT_ROWS = "max_result_rows"; 29 | 30 | /** 31 | * Defines server response if result set exceeded a limit set by {@code max_result_rows}. 32 | * Possible values are 'throw' or 'break'. Default is 'throw' 33 | */ 34 | public static final String RESULT_OVERFLOW_MODE = "result_overflow_mode"; 35 | 36 | public static final String ASYNC_INSERT = "async_insert"; 37 | 38 | public static final String WAIT_ASYNC_INSERT = "wait_for_async_insert"; 39 | } 40 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/internal/StopWatch.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | import com.clickhouse.client.api.metrics.Metric; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class StopWatch implements Metric { 8 | 9 | long elapsedNanoTime = 0; 10 | long startNanoTime; 11 | 12 | public StopWatch() { 13 | // do nothing 14 | } 15 | 16 | public StopWatch(long startNanoTime) { 17 | this.startNanoTime = startNanoTime; 18 | } 19 | 20 | public void start() { 21 | startNanoTime = System.nanoTime(); 22 | } 23 | 24 | public void stop() { 25 | elapsedNanoTime = System.nanoTime() - startNanoTime; 26 | } 27 | 28 | /** 29 | * Returns the elapsed time in milliseconds. 30 | * @return 31 | */ 32 | public long getElapsedTime() { 33 | return TimeUnit.NANOSECONDS.toMillis(elapsedNanoTime); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "{" + 39 | "\"elapsedNanoTime\"=" + elapsedNanoTime + 40 | ", \"elapsedTime\"=" + getElapsedTime() + 41 | '}'; 42 | } 43 | 44 | @Override 45 | public long getLong() { 46 | return getElapsedTime(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/metadata/ColumnToMethodMatchingStrategy.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.metadata; 2 | 3 | 4 | /** 5 | * Strategy to match column names to method names. 6 | */ 7 | public interface ColumnToMethodMatchingStrategy { 8 | 9 | /** 10 | * Normalizes method name to match column name. 11 | * @param methodName original method name 12 | * @return normalized method name 13 | */ 14 | String normalizeMethodName(String methodName); 15 | 16 | /** 17 | * Checks if the method is a setter. 18 | * @param methodName original (not normalized) method name 19 | * @return true if the method is a setter 20 | */ 21 | boolean isSetter(String methodName); 22 | 23 | /** 24 | * Checks if the method is a getter. 25 | * @param methodName original (not normalized) method name 26 | * @return true if the method is a getter 27 | */ 28 | boolean isGetter(String methodName); 29 | 30 | /** 31 | * Normalizes column name to match method name. 32 | * @param columnName original column name 33 | * @return normalized column name 34 | */ 35 | String normalizeColumnName(String columnName); 36 | } 37 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/metadata/NoSuchColumnException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.metadata; 2 | 3 | import com.clickhouse.client.api.ClientException; 4 | 5 | public class NoSuchColumnException extends ClientException { 6 | 7 | public NoSuchColumnException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/metrics/ClientMetrics.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.metrics; 2 | 3 | public enum ClientMetrics { 4 | 5 | /** 6 | * Operation duration in nanoseconds. 7 | */ 8 | OP_DURATION("client.opDuration"), 9 | 10 | /** 11 | * Duration of the operation serialization step in nanoseconds. 12 | */ 13 | OP_SERIALIZATION("client.opSerialization"); 14 | 15 | private final String key; 16 | 17 | ClientMetrics(String key) { 18 | this.key = key; 19 | } 20 | 21 | public String getKey() { 22 | return key; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/metrics/Metric.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.metrics; 2 | 3 | public interface Metric { 4 | 5 | /** 6 | * Returns value of the metric as a long. 7 | * @return value of the metric as a long 8 | */ 9 | long getLong(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/metrics/ServerMetrics.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.metrics; 2 | 3 | /** 4 | * Stats returned by the server. 5 | *

6 | * `-1` means the value is not available. 7 | */ 8 | public enum ServerMetrics { 9 | 10 | /** 11 | * Number of rows read by server from the storage. 12 | */ 13 | NUM_ROWS_READ("server.numRowsRead"), 14 | 15 | /** 16 | * Number of rows written by server to the storage. 17 | */ 18 | NUM_ROWS_WRITTEN("server.numRowsWritten"), 19 | 20 | /** 21 | * Estimated number of rows to read from the storage. 22 | *

23 | */ 24 | TOTAL_ROWS_TO_READ("server.totalRowsToRead"), 25 | 26 | /** 27 | * Number of bytes read by server from the storage. 28 | */ 29 | NUM_BYTES_READ("server.numBytesRead"), 30 | 31 | /** 32 | * Number of bytes written by server to the storage. 33 | */ 34 | NUM_BYTES_WRITTEN("server.numBytesWritten"), 35 | 36 | /** 37 | * Number of returned rows. 38 | */ 39 | RESULT_ROWS("server.resultRows"), 40 | 41 | /** 42 | * Elapsed time in nanoseconds. 43 | */ 44 | ELAPSED_TIME("server.elapsedTime"); 45 | 46 | private final String key; 47 | 48 | ServerMetrics(String key) { 49 | this.key = key; 50 | } 51 | 52 | public String getKey() { 53 | return key; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/query/NullValueException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.query; 2 | 3 | import com.clickhouse.client.api.ClientException; 4 | 5 | /** 6 | * Throw when a null value cannot be returned because of data type. 7 | * For example when a primitive type is expected but a null value is received. 8 | * 9 | */ 10 | public class NullValueException extends ClientException { 11 | public NullValueException(String message) { 12 | super(message); 13 | } 14 | 15 | public NullValueException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/query/QueryStatement.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.query; 2 | 3 | 4 | /** 5 | * QueryStatement class is responsible for constructing SQL query statements. 6 | * 7 | */ 8 | public class QueryStatement { 9 | 10 | private final String query; 11 | 12 | public QueryStatement(String query) { 13 | this.query = query; 14 | } 15 | 16 | public String getQuery() { 17 | return query; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/serde/DataSerializationException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.serde; 2 | 3 | import com.clickhouse.client.api.ClientException; 4 | 5 | public class DataSerializationException extends ClientException { 6 | 7 | public DataSerializationException(String message) { 8 | super(message); 9 | } 10 | 11 | public DataSerializationException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public DataSerializationException(Object obj, POJOFieldSerializer serializer, Exception e) { 16 | super("Failed to serialize data '" + obj + "' with serializer '" + serializer + "'", e); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/serde/POJOFieldDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.serde; 2 | 3 | 4 | import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader; 5 | import com.clickhouse.data.ClickHouseColumn; 6 | 7 | /** 8 | * Class used to set value for individual fields in a POJO. 9 | * Implementation will have reference to a specific POJO property. 10 | * Caller will use this class to set value for the property. 11 | * Methods are overloaded to support primitive types and avoid boxing. 12 | */ 13 | public interface POJOFieldDeserializer { 14 | 15 | void setValue(Object obj, BinaryStreamReader reader, ClickHouseColumn column) throws Exception; 16 | } 17 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/serde/POJOFieldSerializer.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.serde; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.lang.reflect.InvocationTargetException; 6 | 7 | public interface POJOFieldSerializer { 8 | void serialize(Object obj, OutputStream outputStream) throws InvocationTargetException, IllegalAccessException, IOException; 9 | } 10 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/serde/SerializerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.serde; 2 | 3 | import com.clickhouse.client.api.ClientException; 4 | 5 | public class SerializerNotFoundException extends ClientException { 6 | 7 | public SerializerNotFoundException(Class pojoClass) { 8 | super("Serializer not found for the class '" + pojoClass.getName() + "'"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/transport/Endpoint.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.transport; 2 | 3 | /** 4 | * Interface defining the behavior of transport endpoint. 5 | * It is transport responsibility to provide suitable implementation. 6 | */ 7 | public interface Endpoint { 8 | 9 | String getBaseURL(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /client-v2/src/main/java/com/clickhouse/client/api/transport/HttpEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.transport; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URI; 5 | import java.net.URL; 6 | 7 | public class HttpEndpoint implements Endpoint { 8 | 9 | private final URI uri; // contains complete connection URL + parameters 10 | 11 | private final URL url; // only communication part 12 | 13 | private final String baseURL; 14 | 15 | private final String info; 16 | 17 | private final boolean secure; 18 | 19 | public HttpEndpoint(String uri) throws MalformedURLException { 20 | this.uri = URI.create(uri); 21 | this.url = this.uri.toURL(); 22 | this.baseURL = url.toString(); 23 | this.info = baseURL; 24 | this.secure = this.uri.getScheme().equalsIgnoreCase("https"); 25 | } 26 | 27 | @Override 28 | public String getBaseURL() { 29 | return baseURL; 30 | } 31 | 32 | public URL getURL() { 33 | return url; 34 | } 35 | 36 | public URI getURI() { 37 | return uri; 38 | } 39 | 40 | public boolean isSecure() { 41 | return secure; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return info; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /client-v2/src/main/resources/client-v2-version.properties: -------------------------------------------------------------------------------- 1 | version=${revision} 2 | build.date=${build_timestamp} 3 | apache.http.client.version=${apache.httpclient.version} -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/SettingsTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client; 2 | 3 | import com.clickhouse.client.api.Client; 4 | import com.clickhouse.client.api.ClientConfigProperties; 5 | import org.testng.Assert; 6 | import org.testng.annotations.Test; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | public class SettingsTests { 12 | 13 | @Test 14 | void testClientSettings() { 15 | List source = Arrays.asList("ROL1", "ROL2,☺", "Rol,3,3"); 16 | String listA = ClientConfigProperties.commaSeparated(source); 17 | List listB = ClientConfigProperties.valuesFromCommaSeparated(listA); 18 | Assert.assertEquals(listB, source); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/api/DataTypeUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | import static org.testng.AssertJUnit.assertEquals; 8 | 9 | public class DataTypeUtilsTests { 10 | 11 | 12 | @Test 13 | public void testDateTimeFormatter() { 14 | LocalDateTime dateTime = LocalDateTime.of(2021, 12, 31, 23, 59, 59); 15 | String formattedDateTime = dateTime.format(DataTypeUtils.DATETIME_FORMATTER); 16 | assertEquals("2021-12-31 23:59:59", formattedDateTime); 17 | } 18 | 19 | @Test 20 | public void testDateFormatter() { 21 | LocalDateTime date = LocalDateTime.of(2021, 12, 31, 10, 20); 22 | String formattedDate = date.toLocalDate().format(DataTypeUtils.DATE_FORMATTER); 23 | assertEquals("2021-12-31", formattedDate); 24 | } 25 | 26 | @Test 27 | public void testDateTimeWithNanosFormatter() { 28 | LocalDateTime dateTime = LocalDateTime.of(2021, 12, 31, 23, 59, 59, 123456789); 29 | String formattedDateTimeWithNanos = dateTime.format(DataTypeUtils.DATETIME_WITH_NANOS_FORMATTER); 30 | assertEquals("2021-12-31 23:59:59.123456789", formattedDateTimeWithNanos); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReaderTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.data_formats.internal; 2 | 3 | import org.junit.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class BinaryStreamReaderTests { 7 | 8 | 9 | @Test 10 | public void testCachedByteAllocator() { 11 | BinaryStreamReader.CachingByteBufferAllocator allocator = new BinaryStreamReader.CachingByteBufferAllocator(); 12 | 13 | for (int i = 0; i < 6; i++) { 14 | int size = (int) Math.pow(2, i); 15 | byte[] firstAllocation = allocator.allocate(size); 16 | byte[] nextAllocation = allocator.allocate(size); 17 | Assert.assertSame( "Should be the same buffer for size " + size, firstAllocation, nextAllocation); 18 | } 19 | 20 | for (int i = 6; i < 16; i++) { 21 | int size = (int) Math.pow(2, i); 22 | byte[] firstAllocation = allocator.allocate(size); 23 | byte[] nextAllocation = allocator.allocate(size); 24 | Assert.assertNotSame(firstAllocation, nextAllocation); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/SerializerUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.data_formats.internal; 2 | 3 | public class SerializerUtilsTests { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/api/internal/HttpAPIClientHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.api.internal; 2 | 3 | public class HttpAPIClientHelperTest { 4 | 5 | } -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/datatypes/NestedTypesDTO.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.datatypes; 2 | 3 | 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.testng.annotations.Test; 8 | 9 | import static com.clickhouse.client.datatypes.DataTypeTests.tableDefinition; 10 | 11 | @Data 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class NestedTypesDTO { 15 | 16 | private int rowId; 17 | 18 | private Object[] tuple1; 19 | 20 | private double[] point1; 21 | 22 | public static String tblCreateSQL(String table) { 23 | return tableDefinition(table, 24 | "rowId Int16", 25 | "tuple1 Tuple(Int16, String)", 26 | "point1 Point"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/datatypes/VariantDTO.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.datatypes; 2 | 3 | 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import static com.clickhouse.client.datatypes.DataTypeTests.tableDefinition; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class VariantDTO { 14 | 15 | private int rowId; 16 | 17 | private Object a; 18 | 19 | private Object b; 20 | 21 | private Object c; 22 | 23 | private Object d; 24 | 25 | private Object e; 26 | 27 | private Object f; 28 | 29 | public static String tblCreateSQL(String table) { 30 | return tableDefinition(table, 31 | "rowId Int16", 32 | "a Variant(String, Int16)", 33 | "b Variant(String, Int128)", 34 | "c Variant(String, Decimal128(4))", 35 | "d Variant(String, Float32)", 36 | "e Variant(Int128, Decimal128(4))", 37 | "f Variant(Float64, Int128)"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/insert/InsertClientHttpCompressionTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.insert; 2 | 3 | public class InsertClientHttpCompressionTests extends InsertTests { 4 | 5 | public InsertClientHttpCompressionTests() { 6 | super(true, true); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/insert/NoSettersPOJO.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.insert; 2 | 3 | public class NoSettersPOJO { 4 | 5 | private int p1; 6 | 7 | private int p2; 8 | 9 | public NoSettersPOJO(int p1, int p2) { 10 | this.p1 = p1; 11 | this.p2 = p2; 12 | } 13 | 14 | public int sum() { 15 | return p1 + p2; 16 | } 17 | 18 | public static String generateTableCreateSQL(String tableName) { 19 | return "CREATE TABLE " + tableName + " (p1 Int32, p2 Int32) ENGINE = MergeTree() ORDER BY ()"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/insert/PojoWithDynamic.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.insert; 2 | 3 | import com.clickhouse.client.datatypes.DataTypeTests; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | import lombok.NoArgsConstructor; 8 | import lombok.ToString; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @EqualsAndHashCode 14 | @ToString 15 | public class PojoWithDynamic { 16 | 17 | int rowId; 18 | 19 | Object any; 20 | 21 | Object nullableAny; 22 | 23 | public static String getTableDef(String tableName) { 24 | return DataTypeTests.tableDefinition(tableName, 25 | "rowId Int32", 26 | "any Dynamic", 27 | "nullableAny Dynamic"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/insert/PojoWithJSON.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.insert; 2 | 3 | import java.util.Objects; 4 | 5 | public class PojoWithJSON { 6 | 7 | // This field is a string representation of a JSON object 8 | private String eventPayload; 9 | 10 | public String getEventPayload() { 11 | return eventPayload; 12 | } 13 | 14 | public void setEventPayload(String eventPayload) { 15 | this.eventPayload = eventPayload; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object o) { 20 | if (this == o) return true; 21 | if (o == null || getClass() != o.getClass()) return false; 22 | PojoWithJSON that = (PojoWithJSON) o; 23 | return Objects.equals(eventPayload, that.eventPayload); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(eventPayload); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "PojoWithJSON{" + 34 | "eventPayload='" + eventPayload + '\'' + 35 | '}'; 36 | } 37 | 38 | public static String createTable(String tableName) { 39 | return "CREATE TABLE " + tableName + " (eventPayload JSON) ENGINE = MergeTree() ORDER BY tuple()"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/insert/SimplePOJO.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.insert; 2 | 3 | import com.clickhouse.client.ClientTests; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import org.apache.commons.lang3.RandomStringUtils; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.util.Random; 11 | 12 | @Getter 13 | @Setter 14 | public class SimplePOJO { 15 | 16 | private static final Logger LOGGER = LoggerFactory.getLogger(SimplePOJO.class); 17 | private int int32; 18 | private String str; 19 | private String hexed; 20 | 21 | public SimplePOJO() { 22 | long seed = System.currentTimeMillis(); 23 | final Random random = new Random(seed); 24 | this.int32 = random.nextInt(); 25 | this.str = RandomStringUtils.randomAlphabetic(1, 256); 26 | this.hexed = RandomStringUtils.randomAlphanumeric(4); 27 | } 28 | 29 | public static String generateTableCreateSQL(String tableName) { 30 | return "CREATE TABLE " + tableName + " (" + 31 | "int32 Int32, " + 32 | "str String, " + 33 | "int64 Int64 MATERIALIZED abs(toInt64(int32)), " + 34 | "str_lower String ALIAS lower(str), " + 35 | "unhexed String EPHEMERAL, " + 36 | "hexed FixedString(4) DEFAULT unhex(unhexed), " + 37 | ") ENGINE = MergeTree ORDER BY ()"; 38 | } 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/internal/SerializerUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.internal; 2 | 3 | import com.clickhouse.client.api.data_formats.internal.SerializerUtils; 4 | import org.testng.annotations.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | public class SerializerUtilsTests { 9 | 10 | @Test 11 | public void testConvertToInteger() { 12 | int expected = 1640995199; // Unix timestamp for the given date 13 | assertEquals(expected, SerializerUtils.convertToInteger("1640995199").intValue()); 14 | assertEquals(0, SerializerUtils.convertToInteger(false).intValue()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/query/BinaryReadyReusesBuffersTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.query; 2 | 3 | public class BinaryReadyReusesBuffersTests extends QueryTests { 4 | 5 | public BinaryReadyReusesBuffersTests() { 6 | super(false, false, true); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/query/NoGettersPOJO.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.query; 2 | 3 | public class NoGettersPOJO { 4 | 5 | private int p1; 6 | 7 | private int p2; 8 | 9 | public NoGettersPOJO(int p1, int p2) { 10 | this.p1 = p1; 11 | this.p2 = p2; 12 | } 13 | 14 | public int sum() { 15 | return p1 + p2; 16 | } 17 | 18 | public static String generateTableCreateSQL(String tableName) { 19 | return "CREATE TABLE " + tableName + " (p1 Int32, p2 Int32) ENGINE = MergeTree() ORDER BY ()"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/query/QueryServerContentCompressionTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.query; 2 | 3 | public class QueryServerContentCompressionTests extends QueryTests { 4 | 5 | QueryServerContentCompressionTests() { 6 | super(true, false); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/query/QueryServerHttpCompressionTests.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.query; 2 | 3 | public class QueryServerHttpCompressionTests extends QueryTests { 4 | QueryServerHttpCompressionTests() { 5 | super(true, true); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /client-v2/src/test/java/com/clickhouse/client/query/SimplePOJO.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.client.query; 2 | 3 | 4 | public class SimplePOJO { 5 | 6 | long id = 0; 7 | 8 | String name = null; 9 | 10 | Integer age = null; 11 | 12 | Boolean bool = false; 13 | 14 | public long getId() { 15 | return id; 16 | } 17 | 18 | public void setId(long id) { 19 | this.id = id; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public Integer getAge() { 31 | return age; 32 | } 33 | 34 | public void setAge(Integer age) { 35 | this.age = age; 36 | } 37 | 38 | public Boolean getBool() { 39 | return bool; 40 | } 41 | 42 | public void setBool(Boolean bool) { 43 | this.bool = bool; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "SimplePOJO{" + 49 | "id=" + id + 50 | ", name='" + name + '\'' + 51 | ", age=" + age + 52 | ", bool=" + bool + 53 | '}'; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/client-v2/README.md: -------------------------------------------------------------------------------- 1 | # Client V2 Example 2 | 3 | ## Overview 4 | 5 | This example demonstrates how to use the client V2 to interact with the ClickHouse server. 6 | 7 | ## How to Run 8 | 9 | Apache Maven or IDE with Maven support is required to run this example. 10 | 11 | First we need to compile the example : 12 | ```shell 13 | mvn clean compile 14 | ``` 15 | 16 | To run: 17 | ```shell 18 | mvn exec:java -Dexec.mainClass="com.clickhouse.examples.client_v2.Main" 19 | ``` 20 | 21 | Addition options can be passed to the application: 22 | - `-DchEndpoint` - Endpoint to connect in the format of URL (default: http://localhost:8123/) 23 | - `-DchUser` - ClickHouse user name (default: default) 24 | - `-DchPassword` - ClickHouse user password (default: empty) 25 | - `-DchDatabase` - ClickHouse database name (default: default) -------------------------------------------------------------------------------- /examples/client-v2/src/main/java/com/clickhouse/examples/client_v2/data/ArticleViewEvent.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.examples.client_v2.data; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDateTime; 8 | 9 | /** 10 | *

POJO class representing an event emitted by UI to register a fact of an article being viewed. 11 | * It is used to demonstrate how to insert data using new client API.

12 | */ 13 | @AllArgsConstructor 14 | @Data 15 | @NoArgsConstructor 16 | public class ArticleViewEvent { 17 | private Double postId; 18 | private LocalDateTime viewTime; 19 | private String clientId; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /examples/client-v2/src/main/java/com/clickhouse/examples/client_v2/data/NumbersRecord.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service.data; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.math.BigInteger; 8 | import java.util.UUID; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class NumbersRecord { 14 | 15 | private UUID id; 16 | 17 | private long p1; 18 | 19 | private BigInteger number; 20 | 21 | private float p2; 22 | 23 | private double p3; 24 | } 25 | -------------------------------------------------------------------------------- /examples/client-v2/src/main/java/com/clickhouse/examples/client_v2/data/PojoWithJSON.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.examples.client_v2.data; 2 | 3 | import java.util.Objects; 4 | 5 | public class PojoWithJSON { 6 | 7 | // This field is a string representation of a JSON object 8 | private String eventPayload; 9 | 10 | public String getEventPayload() { 11 | return eventPayload; 12 | } 13 | 14 | public void setEventPayload(String eventPayload) { 15 | this.eventPayload = eventPayload; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object o) { 20 | if (this == o) return true; 21 | if (o == null || getClass() != o.getClass()) return false; 22 | PojoWithJSON that = (PojoWithJSON) o; 23 | return Objects.equals(eventPayload, that.eventPayload); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(eventPayload); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "PojoWithJSON{" + 34 | "eventPayload='" + eventPayload + '\'' + 35 | '}'; 36 | } 37 | 38 | public static String createTable(String tableName) { 39 | return "CREATE TABLE " + tableName + " (eventPayload JSON) ENGINE = MergeTree() ORDER BY tuple()"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /examples/client-v2/src/main/resources/article_view_event_init.sql: -------------------------------------------------------------------------------- 1 | create table article_view_events ( 2 | postId Nullable(Float64), 3 | viewTime DateTime DEFAULT now(), 4 | clientId String DEFAULT 'unknown', 5 | ) engine = MergeTree order by (); -------------------------------------------------------------------------------- /examples/client-v2/src/main/resources/simple_writer_init.sql: -------------------------------------------------------------------------------- 1 | create table hacker_news_articles ( 2 | id Nullable(Float64), 3 | deleted Nullable(Float64), 4 | type Nullable(String), 5 | by Nullable(String), 6 | time Nullable(String), 7 | text Nullable(String), 8 | dead Nullable(Float64), 9 | parent Nullable(Float64), 10 | poll Nullable(Float64), 11 | kids Array(Nullable(Float64)), 12 | url Nullable(String), 13 | score Nullable(Float64), 14 | title Nullable(String), 15 | parts Array(Nullable(Float64)), 16 | descendants Nullable(Float64) 17 | ) engine = MergeTree order by (); -------------------------------------------------------------------------------- /examples/client/src/proto/ui_stats_event.proto: -------------------------------------------------------------------------------- 1 | 2 | syntax = "proto3"; 3 | 4 | option java_multiple_files = true; 5 | option java_package = "com.clickhouse.samples.protos"; 6 | option java_outer_classname = "UIStatsEventProtos"; 7 | 8 | message UIEvent { 9 | string url = 1; 10 | string user_id = 2; 11 | string session_id = 3; 12 | int64 timestamp = 4; 13 | int64 duration = 5; 14 | string event = 6; 15 | } 16 | -------------------------------------------------------------------------------- /examples/demo-kotlin-service/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | !**/src/main/**/build/ 5 | !**/src/test/**/build/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | bin/ 16 | !**/src/main/**/bin/ 17 | !**/src/test/**/bin/ 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | out/ 25 | !**/src/main/**/out/ 26 | !**/src/test/**/out/ 27 | 28 | ### NetBeans ### 29 | /nbproject/private/ 30 | /nbbuild/ 31 | /dist/ 32 | /nbdist/ 33 | /.nb-gradle/ 34 | 35 | ### VS Code ### 36 | .vscode/ -------------------------------------------------------------------------------- /examples/demo-kotlin-service/build.gradle.kts: -------------------------------------------------------------------------------- 1 | 2 | val kotlin_version: String by project 3 | val logback_version: String by project 4 | val ktor_version: String by project 5 | 6 | plugins { 7 | kotlin("jvm") version "2.0.20" 8 | id("io.ktor.plugin") version "2.3.12" 9 | } 10 | 11 | group = "com.clickhouse" 12 | version = "0.0.1" 13 | 14 | application { 15 | mainClass.set("io.ktor.server.netty.EngineMain") 16 | 17 | val isDevelopment: Boolean = project.ext.has("development") 18 | applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") 19 | } 20 | 21 | repositories { 22 | mavenLocal() // comment to pull nightly builds instead of local cache 23 | mavenCentral() 24 | maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") // for nightly builds 25 | } 26 | 27 | val ch_java_client_version: String by extra 28 | 29 | dependencies { 30 | // application dependencies 31 | implementation("io.ktor:ktor-server-core-jvm") 32 | implementation("io.ktor:ktor-server-netty-jvm") 33 | implementation("ch.qos.logback:logback-classic:$logback_version") 34 | implementation("io.ktor:ktor-server-config-yaml") 35 | implementation("io.ktor:ktor-server-content-negotiation:$ktor_version") 36 | implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version") 37 | 38 | // https://mvnrepository.com/artifact/com.clickhouse/client-v2 39 | implementation("com.clickhouse:client-v2:${ch_java_client_version}-SNAPSHOT:all") 40 | // implementation("com.clickhouse:client-v2:${ch_java_client_version}:all") // release version 41 | 42 | testImplementation("io.ktor:ktor-server-test-host-jvm") 43 | testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") 44 | } 45 | -------------------------------------------------------------------------------- /examples/demo-kotlin-service/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | ktor_version=2.3.12 3 | kotlin_version=2.0.20 4 | logback_version=1.4.14 5 | 6 | ch_java_client_version=0.8.6 -------------------------------------------------------------------------------- /examples/demo-kotlin-service/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/examples/demo-kotlin-service/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/demo-kotlin-service/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /examples/demo-kotlin-service/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "com.clickhouse.examples" 2 | -------------------------------------------------------------------------------- /examples/demo-kotlin-service/src/main/kotlin/com/clickhouse/examples/service/Application.kt: -------------------------------------------------------------------------------- 1 | package com.clickhouse.examples.service 2 | 3 | import io.ktor.serialization.kotlinx.json.* 4 | import io.ktor.server.application.* 5 | import io.ktor.server.plugins.contentnegotiation.* 6 | 7 | fun main(args: Array) { 8 | io.ktor.server.netty.EngineMain.main(args) 9 | } 10 | 11 | fun Application.configureDatabase(env: ApplicationEnvironment) { 12 | Database.connect( 13 | env.config.property("ktor.database.url").getString(), 14 | env.config.property("ktor.database.user").getString(), 15 | env.config.property("ktor.database.password").getString() 16 | ) 17 | } 18 | 19 | fun Application.module() { 20 | install(ContentNegotiation) { 21 | json() 22 | } 23 | configureRouting() 24 | configureDatabase(environment) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /examples/demo-kotlin-service/src/main/kotlin/com/clickhouse/examples/service/Database.kt: -------------------------------------------------------------------------------- 1 | package com.clickhouse.examples.service 2 | 3 | import com.clickhouse.client.api.Client 4 | import com.clickhouse.client.api.query.GenericRecord 5 | 6 | object Database { 7 | 8 | private var client: Client? = null 9 | 10 | fun connect(dbUrl: String, dbUser: String, dbPassword: String) { 11 | println("Connecting to ClickHouse using $dbUrl...") 12 | client = Client.Builder() 13 | .addEndpoint(dbUrl) 14 | .setUsername(dbUser) 15 | .setPassword(dbPassword) 16 | .useNewImplementation(true) 17 | .build() 18 | } 19 | 20 | fun query(query: String): List? { 21 | return client!!.queryAll(query) 22 | } 23 | } -------------------------------------------------------------------------------- /examples/demo-kotlin-service/src/main/kotlin/com/clickhouse/examples/service/Routing.kt: -------------------------------------------------------------------------------- 1 | package com.clickhouse.examples.service 2 | 3 | import io.ktor.server.application.* 4 | import io.ktor.server.response.* 5 | import io.ktor.server.routing.* 6 | 7 | fun Application.configureRouting() { 8 | routing { 9 | get("/numbers") { 10 | val limit = call.request.queryParameters["limit"]?.toIntOrNull() ?: 10 11 | val numbers = Database.query("SELECT toUInt32(number) FROM system.numbers LIMIT $limit")!! 12 | .map { it.getLong(1) } 13 | 14 | call.respond(numbers) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/demo-kotlin-service/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | ktor: 2 | application: 3 | modules: 4 | - com.clickhouse.examples.service.ApplicationKt.module 5 | deployment: 6 | port: 8080 7 | database: 8 | url: 'http://localhost:8123/default' 9 | user: 'default' 10 | password: '' -------------------------------------------------------------------------------- /examples/demo-kotlin-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/demo-service/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /examples/demo-service/gradle.properties: -------------------------------------------------------------------------------- 1 | 2 | ch_java_client_version=0.8.6 -------------------------------------------------------------------------------- /examples/demo-service/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/examples/demo-service/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/demo-service/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /examples/demo-service/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "demo-service" 2 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/java/com/clickhouse/demo_service/BasicObjectsPool.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service; 2 | 3 | import java.util.Deque; 4 | 5 | /** 6 | * Very basic object pool implementation. 7 | * It uses a deque to store objects. Leased objects are removed from the 8 | * deque and released objects are added back to the deque. When there is no objects in the deque, 9 | * a new object is created (assuming it will be returned on release). 10 | * 11 | * @param 12 | */ 13 | public abstract class BasicObjectsPool { 14 | 15 | private Deque objects; 16 | 17 | BasicObjectsPool(Deque objects) { 18 | this(objects, 0); 19 | } 20 | 21 | BasicObjectsPool(Deque objects, int size) { 22 | this.objects = objects; 23 | for (int i = 0; i < size; i++) { 24 | this.objects.add(create()); 25 | } 26 | } 27 | 28 | public T lease() { 29 | T obj = objects.poll(); 30 | return obj != null ? obj : create(); 31 | } 32 | 33 | public void release(T obj) { 34 | objects.addFirst(obj); 35 | } 36 | 37 | abstract T create(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/java/com/clickhouse/demo_service/CalculationResult.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service; 2 | 3 | public class CalculationResult { 4 | 5 | long p1; 6 | 7 | public CalculationResult(long p1) { 8 | this.p1 = p1; 9 | } 10 | 11 | public long getP1() { 12 | return p1; 13 | } 14 | 15 | public void setP1(long p1) { 16 | this.p1 = p1; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/java/com/clickhouse/demo_service/DemoServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoServiceApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/java/com/clickhouse/demo_service/ObjectsPreparedCollection.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service; 2 | 3 | import java.util.Deque; 4 | import java.util.Iterator; 5 | import java.util.function.Supplier; 6 | 7 | /** 8 | * This is a prepared collection of objects. It is aimed to solve the problem of 9 | * creating and releasing objects in a loop. After all objects are used, the collection 10 | * should be reset. 11 | * 12 | * 13 | * @param 14 | */ 15 | public abstract class ObjectsPreparedCollection implements Supplier { 16 | 17 | private Deque objects; 18 | 19 | private Iterator iterator; 20 | 21 | ObjectsPreparedCollection(Deque objects) { 22 | this(objects, 0); 23 | } 24 | 25 | ObjectsPreparedCollection(Deque objects, int size) { 26 | this.objects = objects; 27 | for (int i = 0; i < size; i++) { 28 | this.objects.add(create()); 29 | } 30 | this.reset(); 31 | } 32 | 33 | @Override 34 | public T get() { 35 | T obj; 36 | if (iterator.hasNext()) { 37 | obj = iterator.next(); 38 | } else { 39 | obj = create(); 40 | objects.addFirst(obj); 41 | } 42 | 43 | return obj; 44 | } 45 | 46 | public void reset() { 47 | this.iterator = objects.iterator(); 48 | } 49 | abstract T create(); 50 | } 51 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/java/com/clickhouse/demo_service/data/UIEvent.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service.data; 2 | 3 | import com.clickhouse.demo_service.jpa.ClickHouseStringArrayType; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.Id; 6 | import jakarta.persistence.Table; 7 | import lombok.Data; 8 | import org.hibernate.annotations.Array; 9 | import org.hibernate.annotations.JdbcType; 10 | import org.hibernate.annotations.Type; 11 | import org.hibernate.type.descriptor.jdbc.ArrayJdbcType; 12 | 13 | import java.sql.JDBCType; 14 | import java.sql.Timestamp; 15 | import java.util.Collection; 16 | import java.util.List; 17 | 18 | @Entity 19 | @Data 20 | @Table(name = "ui_events") 21 | public class UIEvent { 22 | 23 | @Id 24 | private String id; 25 | 26 | private Timestamp timestamp; 27 | 28 | private String eventName; 29 | 30 | @JdbcType(ArrayJdbcType.class) 31 | @Type(ClickHouseStringArrayType.class) 32 | private Collection tags; 33 | } 34 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/java/com/clickhouse/demo_service/data/VirtualDatasetRecord.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service.data; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.math.BigInteger; 9 | import java.util.UUID; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @ToString 15 | public class VirtualDatasetRecord { 16 | 17 | private UUID id; 18 | 19 | private long p1; 20 | 21 | private BigInteger number; 22 | 23 | private float p2; 24 | 25 | private double p3; 26 | } 27 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/java/com/clickhouse/demo_service/jpa/UIEventsDbRepository.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.demo_service.jpa; 2 | 3 | import com.clickhouse.demo_service.data.UIEvent; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.UUID; 8 | 9 | @Repository 10 | public interface UIEventsDbRepository extends JpaRepository { 11 | } 12 | -------------------------------------------------------------------------------- /examples/demo-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=demo-service 2 | 3 | 4 | app.log_metrics=false 5 | db.url=http://localhost:8123/default 6 | db.user=default 7 | db.pass=secret 8 | 9 | 10 | spring.jpa.properties.hibernate.dialect=org.hibernate.annotations.processing.GenericDialect 11 | spring.jpa.hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider 12 | spring.jpa.show-sql=true 13 | spring.jpa.hibernate.ddl-auto=validate 14 | 15 | spring.datasource.url=jdbc:ch:http//${CH_ADDRESS:localhost:8123}/default 16 | spring.datasource.username=${db.user} 17 | spring.datasource.password=${db.pass} 18 | spring.datasource.driver-class-name=com.clickhouse.jdbc.ClickHouseDriver 19 | 20 | spring.datasource.hikari.connection-timeout=30000 21 | spring.datasource.hikari.idle-timeout=20000 22 | spring.datasource.hikari.max-lifetime=300000 23 | spring.datasource.hikari.maximum-pool-size=100 24 | spring.datasource.hikari.minimum-idle=1 25 | spring.datasource.hikari.pool-name=ChConnPool 26 | spring.datasource.hikari.connection-test-query=select 1 27 | 28 | # To not throw exception on unsupported operations 29 | spring.datasource.hikari.dataSourceProperties.jdbc_ignore_unsupported_values=true 30 | 31 | 32 | logging.level.com.zaxxer.hikari.HikariConfig=DEBUG 33 | logging.level.com.zaxxer.hikari=TRACE -------------------------------------------------------------------------------- /examples/demo-service/src/test/java/com/clickhouse/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/examples/demo-service/src/test/java/com/clickhouse/.keep -------------------------------------------------------------------------------- /examples/jdbc/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Example of ClickHouse JDBC Client Usage 3 | 4 | This example application uses JDBC to interact with ClickHouse Server. 5 | 6 | 7 | ## Usage 8 | 9 | Apache Maven or IDE with Maven support is required to run this example. 10 | 11 | To compile: 12 | ```shell 13 | mvn clean compile 14 | ``` 15 | 16 | To run simplified example: 17 | ```shell 18 | mvn exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic" 19 | ``` 20 | 21 | Addition options can be passed to the application: 22 | - `-DchUrl` - ClickHouse JDBC URL. Default is `jdbc:clickhouse://localhost:8123/default` 23 | - `-Dclickhouse.jdbc.v2=true` - Use JDBC V2 implementation -------------------------------------------------------------------------------- /examples/r2dbc/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Example of ClickHouse Reactive Client Usage 3 | 4 | This type of client still uses HTTP protocol to communicate with ClickHouse server, 5 | but it has another mechanism of working with IO - when CPU time utilizes more efficiently 6 | by avoiding blocking operations. 7 | DB interface is exposed via [r2dbc](https://r2dbc.io/) specification. 8 | 9 | ## Usage 10 | 11 | Apache Maven or IDE with Maven support is required to run this example. 12 | 13 | To compile: 14 | ```shell 15 | mvn clean compile 16 | ``` 17 | 18 | Init DB (from resource/init.sql): 19 | ```sql 20 | create database clickdb; 21 | 22 | create table if not exists clickdb.clicks 23 | ( 24 | domain String, 25 | path String, 26 | cdate DateTime, 27 | count UInt64 28 | ) 29 | engine = SummingMergeTree(count) 30 | order by (domain, path, cdate); 31 | ``` 32 | 33 | To run application : 34 | ```shell 35 | cd clickhouse-r2dbc-spring-webflux-sample 36 | mvn exec:java -Dclickhouse.database=default -Dexec.mainClass="com.clickhouse.r2dbc.spring.webflux.sample.Application" 37 | 38 | ``` 39 | 40 | To test the application (run in another terminal): 41 | ```shell 42 | # add clicks 43 | curl -v -X POST -H "application/json" -d '{"domain": "example.org", "path": "/test"}' http://localhost:8080/clicks 44 | 45 | # get counters 46 | curl -v http://localhost:8080/clicks/example.org/ 47 | ``` 48 | 49 | Addition options can be passed to the application: 50 | - `-Dclickhouse.host` - ClickHouse server host 51 | - `-Dclickhouse.port` - ClickHouse server port 52 | - `-Dclickhouse.user` - ClickHouse user name 53 | - `-Dclickhouse.password` - ClickHouse user password 54 | - `-Dclickhouse.database` - ClickHouse database name 55 | -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/README.md: -------------------------------------------------------------------------------- 1 | #clickhouse-r2dbc-spring-webflux-sample 2 | 3 | This is a sample rest api which will insert clicks and get the list of clicks per day. 4 | 5 | In order to run the application; 6 | 7 | - Go clickhouse-java/examples/clickhouse-r2dbc-samples/misc/docker and run `docker-compose up -d` 8 | - Execute the table creation sql at clickhouse-java/examples/clickhouse-r2dbc-samples/clickhouse-r2dbc-spring-webflux-sample/src/main/resources/init.sql. 9 | - Import the postman export clickhouse-java/examples/clickhouse-r2dbc-samples/clickhouse-r2dbc-spring-webflux-sample/src/main/resources/postman. 10 | - Run the application by using Application.java. 11 | - Create some clicks by postman and list daily clicks per domain and path. 12 | -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/java/com/clickhouse/r2dbc/spring/webflux/sample/Application.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.spring.webflux.sample; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.data.r2dbc.R2dbcDataAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration; 7 | import org.springframework.web.reactive.config.EnableWebFlux; 8 | 9 | @SpringBootApplication(exclude = { R2dbcAutoConfiguration.class, 10 | R2dbcDataAutoConfiguration.class}) 11 | @EnableWebFlux 12 | public class Application { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(Application.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/java/com/clickhouse/r2dbc/spring/webflux/sample/config/R2DBCConfig.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.spring.webflux.sample.config; 2 | 3 | import io.r2dbc.spi.ConnectionFactory; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import static io.r2dbc.spi.ConnectionFactories.get; 9 | import static java.lang.String.format; 10 | 11 | @Configuration 12 | public class R2DBCConfig { 13 | 14 | @Value("${clickhouse.host:localhost}") 15 | private String host; 16 | 17 | @Value("${clickhouse.port:8123}") 18 | private String port; 19 | 20 | @Value("${clickhouse.database:clickdb}") 21 | private String database; 22 | 23 | @Value("${clickhouse.user:default}") 24 | private String user; 25 | 26 | @Value("${clickhouse.password:''}") 27 | private String password; 28 | 29 | @Bean 30 | public ConnectionFactory connectionFactory() { 31 | return get(format("r2dbc:clickhouse:http://%s:%s@%s:%d/%s", user, password, 32 | host, Integer.parseInt(port), database)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/java/com/clickhouse/r2dbc/spring/webflux/sample/model/Click.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.spring.webflux.sample.model; 2 | 3 | 4 | public class Click { 5 | 6 | String domain; 7 | String path; 8 | 9 | public String getDomain() { 10 | return domain; 11 | } 12 | 13 | public String getPath() { 14 | return path; 15 | } 16 | 17 | public void setDomain(String domain) { 18 | this.domain = domain; 19 | } 20 | 21 | public void setPath(String path) { 22 | this.path = path; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/java/com/clickhouse/r2dbc/spring/webflux/sample/model/ClickStats.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.r2dbc.spring.webflux.sample.model; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | 6 | import java.time.LocalDate; 7 | 8 | public class ClickStats { 9 | private String domain; 10 | private String path; 11 | @JsonFormat(pattern = "yyyy-MM-dd") 12 | private LocalDate cdate; 13 | private long count; 14 | 15 | public ClickStats(String domain, String path, LocalDate date, long count) { 16 | this.domain = domain; 17 | this.path = path; 18 | this.cdate = date; 19 | this.count = count; 20 | } 21 | 22 | public String getDomain() { 23 | return domain; 24 | } 25 | 26 | public String getPath() { 27 | return path; 28 | } 29 | 30 | public void setDomain(String domain) { 31 | this.domain = domain; 32 | } 33 | 34 | public void setPath(String path) { 35 | this.path = path; 36 | } 37 | 38 | public long getCount() { 39 | return count; 40 | } 41 | 42 | public void setCount(long count) { 43 | this.count = count; 44 | } 45 | 46 | public LocalDate getCdate() { 47 | return cdate; 48 | } 49 | 50 | public void setCdate(LocalDate cdate) { 51 | this.cdate = cdate; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | clickhouse: 2 | host: localhost 3 | port: 8123 4 | database: clickdb 5 | user: default 6 | password: "" 7 | debug: true -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/resources/init.sql: -------------------------------------------------------------------------------- 1 | create database clickdb; 2 | 3 | create table if not exists clickdb.clicks 4 | ( 5 | domain String, 6 | path String, 7 | cdate DateTime, 8 | count UInt64 9 | ) 10 | engine = SummingMergeTree(count) 11 | order by (domain, path, cdate); -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootCategory=DEBUG, stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 4 | log4j.appender.stdout.layout.ConversionPattern=%d{yy-MM-dd HH:mm:ss:SSS} %5p %t %c{2}:%L - %m%n -------------------------------------------------------------------------------- /examples/r2dbc/clickhouse-r2dbc-spring-webflux-sample/src/main/resources/postman/clickhouse-r2dbc-sample.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "42544c65-9bda-4155-b00c-68bf62de19c2", 4 | "name": "clickhouse-r2dbc-sample", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "List Clicks", 10 | "request": { 11 | "method": "GET", 12 | "header": [], 13 | "url": { 14 | "raw": "http://localhost:8080/clicks/google.com", 15 | "protocol": "http", 16 | "host": [ 17 | "localhost" 18 | ], 19 | "port": "8080", 20 | "path": [ 21 | "clicks", 22 | "google.com" 23 | ] 24 | } 25 | }, 26 | "response": [] 27 | }, 28 | { 29 | "name": "Create Clicks", 30 | "request": { 31 | "method": "POST", 32 | "header": [], 33 | "body": { 34 | "mode": "raw", 35 | "raw": "{\n \"domain\" : \"google.com\",\n \"path\" : \"/mail\"\n}", 36 | "options": { 37 | "raw": { 38 | "language": "json" 39 | } 40 | } 41 | }, 42 | "url": { 43 | "raw": "http://localhost:8080/clicks", 44 | "protocol": "http", 45 | "host": [ 46 | "localhost" 47 | ], 48 | "port": "8080", 49 | "path": [ 50 | "clicks" 51 | ] 52 | } 53 | }, 54 | "response": [] 55 | } 56 | ] 57 | } -------------------------------------------------------------------------------- /examples/r2dbc/misc/docker/clickhouse-docker-mount/config.d/docker_related_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | :: 4 | 0.0.0.0 5 | 1 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /examples/r2dbc/misc/docker/clickhouse-docker-mount/docker_related_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | :: 4 | 0.0.0.0 5 | 1 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /examples/r2dbc/misc/docker/compose.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | db: 3 | image: clickhouse/clickhouse-server:22.8 4 | ports: 5 | - 8123:8123 6 | - 9009:9009 7 | - 9100:9100 8 | - 9000:9000 9 | volumes: 10 | - ./clickhouse-docker-mount:/etc/clickhouse-server -------------------------------------------------------------------------------- /examples/r2dbc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | com.clickhouse 7 | clickhouse-r2dbc-samples 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | 12 | clickhouse-r2dbc-spring-webflux-sample 13 | 14 | 15 | -------------------------------------------------------------------------------- /jdbc-v2/README.md: -------------------------------------------------------------------------------- 1 | # ClickHouse JDBC driver 2 | The official JDBC driver for ClickHouse 3 | ## Documentation 4 | See the [ClickHouse website](https://clickhouse.com/docs/en/integrations/language-clients/java/jdbc) for the full documentation entry. 5 | 6 | ## Examples 7 | For more example please check [here](https://github.com/ClickHouse/clickhouse-java/tree/main/examples/jdbc). -------------------------------------------------------------------------------- /jdbc-v2/src/main/java/com/clickhouse/data/Tuple.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.data; 2 | 3 | public class Tuple { 4 | private final Object[] values; 5 | private volatile String output; 6 | public Tuple(Object... values) { 7 | this.values = values; 8 | } 9 | 10 | public Object[] getValues() { 11 | return values; 12 | } 13 | 14 | public Object getValue(int index) { 15 | return values[index]; 16 | } 17 | 18 | public int size() { 19 | return values.length; 20 | } 21 | private String buildOutput() { 22 | StringBuilder sb = new StringBuilder(); 23 | sb.append("("); 24 | for (int i = 0; i < values.length; i++) { 25 | if (i > 0) { 26 | sb.append(", "); 27 | } 28 | sb.append(values[i]); 29 | } 30 | sb.append(")"); 31 | return sb.toString(); 32 | } 33 | @Override 34 | public String toString() { 35 | if (output == null) { 36 | output = buildOutput(); 37 | } 38 | return output; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jdbc-v2/src/main/java/com/clickhouse/jdbc/JdbcV2Wrapper.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc; 2 | 3 | import java.sql.SQLException; 4 | import java.sql.Wrapper; 5 | 6 | public interface JdbcV2Wrapper extends Wrapper { 7 | default boolean isWrapperFor(Class iface) throws SQLException { 8 | return iface != null && iface.isAssignableFrom(getClass()); 9 | } 10 | 11 | @SuppressWarnings("unchecked") 12 | default T unwrap(Class iface) throws SQLException { 13 | if (isWrapperFor(iface)) { 14 | return iface.cast(this); 15 | } 16 | throw new SQLException("Cannot unwrap to " + iface.getName()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ClientInfoProperties.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc.internal; 2 | 3 | public enum ClientInfoProperties { 4 | 5 | APPLICATION_NAME("ApplicationName", 255, "", "Client application name."), 6 | ; 7 | 8 | private String key; 9 | private int maxValue; 10 | 11 | private String defaultValue; 12 | 13 | private String description; 14 | 15 | ClientInfoProperties(String key, int maxValue, String defaultValue, String description) { 16 | this.key = key; 17 | this.maxValue = maxValue; 18 | this.defaultValue = defaultValue; 19 | this.description = description; 20 | } 21 | 22 | public String getKey() { 23 | return key; 24 | } 25 | 26 | public int getMaxValue() { 27 | return maxValue; 28 | } 29 | 30 | public String getDefaultValue() { 31 | return defaultValue; 32 | } 33 | 34 | public String getDescription() { 35 | return description; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jdbc-v2/src/main/java11/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Declares com.clickhouse module. 3 | */ 4 | module com.clickhouse.jdbc { 5 | exports com.clickhouse.jdbc; 6 | 7 | requires java.sql; 8 | 9 | requires transitive com.clickhouse.client; 10 | // requires transitive com.google.gson; 11 | // requires transitive org.lz4.java; 12 | 13 | uses com.clickhouse.client.ClickHouseClient; 14 | uses com.clickhouse.client.ClickHouseDnsResolver; 15 | uses com.clickhouse.client.ClickHouseSslContextProvider; 16 | uses com.clickhouse.data.ClickHouseDataStreamFactory; 17 | uses com.clickhouse.logging.LoggerFactory; 18 | } 19 | -------------------------------------------------------------------------------- /jdbc-v2/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-jdbc/native-image.properties: -------------------------------------------------------------------------------- 1 | Args = -H:ReflectionConfigurationResources=${.}/reflect-config.json 2 | -------------------------------------------------------------------------------- /jdbc-v2/src/main/resources/META-INF/native-image/com.clickhouse/clickhouse-jdbc/reflect-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4HCJNICompressor", 4 | "fields": [{ "name": "INSTANCE" }], 5 | "methods": [{ "name": "", "parameterTypes": ["int"] }] 6 | }, 7 | { 8 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4HCJavaUnsafeCompressor", 9 | "fields": [{ "name": "INSTANCE" }], 10 | "methods": [{ "name": "", "parameterTypes": ["int"] }] 11 | }, 12 | { 13 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JNICompressor", 14 | "fields": [{ "name": "INSTANCE" }] 15 | }, 16 | { 17 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JNIFastDecompressor", 18 | "fields": [{ "name": "INSTANCE" }] 19 | }, 20 | { 21 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JNISafeDecompressor", 22 | "fields": [{ "name": "INSTANCE" }] 23 | }, 24 | { 25 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JavaUnsafeCompressor", 26 | "fields": [{ "name": "INSTANCE" }] 27 | }, 28 | { 29 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JavaUnsafeFastDecompressor", 30 | "fields": [{ "name": "INSTANCE" }] 31 | }, 32 | { 33 | "name": "com.clickhouse.client.internal.jpountz.lz4.LZ4JavaUnsafeSafeDecompressor", 34 | "fields": [{ "name": "INSTANCE" }] 35 | } 36 | ] 37 | -------------------------------------------------------------------------------- /jdbc-v2/src/main/resources/META-INF/services/java.sql.Driver: -------------------------------------------------------------------------------- 1 | com.clickhouse.jdbc.Driver 2 | -------------------------------------------------------------------------------- /jdbc-v2/src/main/resources/jdbc-v2-version.properties: -------------------------------------------------------------------------------- 1 | version=${revision} 2 | build.date=${build_timestamp} -------------------------------------------------------------------------------- /jdbc-v2/src/test/java/com/clickhouse/jdbc/ResultSetImplTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc; 2 | 3 | import static org.testng.Assert.assertEquals; 4 | import static org.testng.Assert.assertTrue; 5 | 6 | import java.sql.Connection; 7 | import java.sql.ResultSet; 8 | import java.sql.SQLException; 9 | import java.sql.Statement; 10 | 11 | import org.testng.annotations.Test; 12 | 13 | public class ResultSetImplTest extends JdbcIntegrationTest { 14 | 15 | @Test(groups = "integration") 16 | public void shouldReturnColumnIndex() throws SQLException { 17 | runQuery("CREATE TABLE rs_test_data (id UInt32, val UInt8) ENGINE = MergeTree ORDER BY (id)"); 18 | runQuery("INSERT INTO rs_test_data VALUES (1, 10), (2, 20)"); 19 | 20 | try (Connection conn = getJdbcConnection()) { 21 | try (Statement stmt = conn.createStatement()) { 22 | try (ResultSet rs = stmt.executeQuery("SELECT * FROM rs_test_data ORDER BY id")) { 23 | assertTrue(rs.next()); 24 | assertEquals(rs.findColumn("id"), 1); 25 | assertEquals(rs.getInt(1), 1); 26 | assertEquals(rs.findColumn("val"), 2); 27 | assertEquals(rs.getInt(2), 10); 28 | 29 | assertTrue(rs.next()); 30 | assertEquals(rs.findColumn("id"), 1); 31 | assertEquals(rs.getInt(1), 2); 32 | assertEquals(rs.findColumn("val"), 2); 33 | assertEquals(rs.getInt(2), 20); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.jdbc.internal; 2 | 3 | public class JdbcUtilsTest { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /jdbc-v2/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | org.slf4j.simpleLogger.log.com.clickhouse.jdbc=debug 3 | org.slf4j.simpleLogger.showDateTime=true 4 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z 5 | org.slf4j.simpleLogger.showThreadName=true 6 | org.slf4j.simpleLogger.showLogName=true 7 | org.slf4j.simpleLogger.showShortLogName=true 8 | -------------------------------------------------------------------------------- /performance/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## JMH Benchmarks 3 | 4 | 5 | ### Dependencies 6 | 7 | 8 | 9 | ### How to Run 10 | 11 | 12 | #### Generating Dataset 13 | 14 | ```shell 15 | mvn compile exec:exec -Dexec.executable=java -Dexec.args="-classpath %classpath com.clickhouse.benchmark.data.DataSetGenerator \ 16 | -input sample_dataset.sql -name default -rows 10" 17 | ``` 18 | 19 | #### Running Benchmarks 20 | 21 | With default settings : 22 | ```shell 23 | mvn compile exec:exec 24 | ``` 25 | 26 | With custom measurement iterations: 27 | ```shell 28 | mvn compile exec:exec -Dexec.executable=java -Dexec.args="-classpath %classpath com.clickhouse.benchmark.BenchmarkRunner -m 3" 29 | ``` 30 | 31 | Other options: 32 | - "-d" - dataset name or file path (like `file://default.csv`) 33 | - "-l" - dataset limits to test coma separated (ex.: `-l 10000,10000`) 34 | - "-m" - number of measurement iterations 35 | - "-t" - time in seconds per iteration 36 | - "-b" - benchmark mask coma separated. Ex.: `-b writer,reader,i`. Default : `-b i,q` 37 | - "all" - Run alpl benchmarks 38 | - "i" - InsertClient - insert operation benchmarks 39 | - "q" - QueryClient - query operation benchmarks 40 | - "ci" - ConcurrentInsertClient - concurrent version of insert benchmarks 41 | - "cq" - ConcurrentQueryClient - concurrent version of query benchmarks 42 | - "lz" - Compression - compression related benchmarks 43 | - "writer" - Serializer - serialization only logic benchmarks 44 | - "reader" - DeSerilalizer - deserialization only logic benchmarks 45 | - "mixed" - MixedWorkload 46 | - "jq" - JDBCQuery - query operations using JDBC 47 | - "ji" - JDBCInsert - insert operation using JDBC -------------------------------------------------------------------------------- /performance/sample_dataset.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE big_columns_example 2 | ( 3 | -- Float64 columns 4 | float_col_1 Float64, 5 | float_col_2 Float64, 6 | float_col_3 Float64, 7 | float_col_4 Float64, 8 | float_col_5 Float64, 9 | float_col_6 Float64, 10 | float_col_7 Float64, 11 | float_col_8 Float64, 12 | float_col_9 Float64, 13 | float_col_10 Float64, 14 | 15 | -- String columns 16 | str_col_1 String, 17 | str_col_2 String, 18 | str_col_3 String, 19 | str_col_4 String, 20 | str_col_5 String, 21 | str_col_6 String, 22 | str_col_7 String, 23 | str_col_8 String, 24 | str_col_9 String, 25 | str_col_10 String, 26 | 27 | -- Int64 columns 28 | int_col_1 Int64, 29 | int_col_2 Int64, 30 | int_col_3 Int64, 31 | int_col_4 Int64, 32 | int_col_5 Int64, 33 | int_col_6 Int64, 34 | int_col_7 Int64, 35 | int_col_8 Int64, 36 | int_col_9 Int64, 37 | int_col_10 Int64 38 | ) 39 | ENGINE = MergeTree 40 | ORDER BY tuple(); 41 | -------------------------------------------------------------------------------- /performance/src/main/java/com/clickhouse/benchmark/data/DataSets.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark.data; 2 | 3 | import com.clickhouse.data.ClickHouseFormat; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import java.nio.charset.StandardCharsets; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.stream.Collectors; 12 | 13 | 14 | public class DataSets { 15 | private static final Logger LOGGER = LoggerFactory.getLogger(DataSets.class); 16 | private static final Map sets; 17 | static { 18 | sets = Map.of( 19 | "simple", new SimpleDataSet() 20 | ); 21 | } 22 | 23 | public static DataSet from(String name) { 24 | return sets.get(name); 25 | } 26 | 27 | public static List convert(List> data, ClickHouseFormat format) { 28 | List bytes = new ArrayList<>(data.size()); 29 | 30 | switch (format) { 31 | case JSONEachRow: 32 | for (Map row : data) { 33 | String json = row.entrySet().stream() 34 | .map(entry -> "\"" + entry.getKey() + "\":\"" + entry.getValue() + "\"") 35 | .collect(Collectors.joining(", ", "{", "}")); 36 | json += "\n"; 37 | bytes.add(json.getBytes(StandardCharsets.UTF_8)); 38 | } 39 | return bytes; 40 | default: 41 | throw new IllegalArgumentException("Unsupported format: " + format); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /performance/src/main/java/com/clickhouse/benchmark/data/SyntheticDataSet.java: -------------------------------------------------------------------------------- 1 | package com.clickhouse.benchmark.data; 2 | 3 | import com.clickhouse.data.format.BinaryStreamUtils; 4 | 5 | import java.io.ByteArrayOutputStream; 6 | import java.time.LocalDateTime; 7 | import java.util.TimeZone; 8 | 9 | public class SyntheticDataSet { 10 | 11 | private final int capacity; 12 | 13 | public SyntheticDataSet(int capacity) { 14 | this.capacity = capacity; 15 | generateData(); 16 | } 17 | 18 | private void generateData() { 19 | generateDateTimeValues(); 20 | } 21 | 22 | private void generateDateTimeValues() { 23 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 24 | dateTimeValues = new LocalDateTime[capacity]; 25 | TimeZone tz = TimeZone.getTimeZone("UTC"); 26 | 27 | try { 28 | for (int i = 0; i < capacity; i++) { 29 | dateTimeValues[i] = LocalDateTime.now().plusSeconds(i); 30 | BinaryStreamUtils.writeDateTime64(out, dateTimeValues[i], 3, tz); 31 | 32 | } 33 | } catch (Exception e) { 34 | throw new RuntimeException("Failed to generate date time values", e); 35 | } 36 | dateTimeValuesRowBinary = out.toByteArray(); 37 | } 38 | 39 | private LocalDateTime[] dateTimeValues; 40 | 41 | private byte[] dateTimeValuesRowBinary; 42 | 43 | public LocalDateTime[] getDateTimeValues() { 44 | return dateTimeValues; 45 | } 46 | 47 | public byte[] getDateTimeValuesRowBinaryStream() { 48 | return dateTimeValuesRowBinary; 49 | } 50 | } -------------------------------------------------------------------------------- /performance/src/test/com/clickhouse/benchmark/BenchmarkRunner.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ClickHouse/clickhouse-java/f0ed7137798492f385a9bb999e88a2bc99cdfd80/performance/src/test/com/clickhouse/benchmark/BenchmarkRunner.java -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo $1 4 | RELEASE_VERSION=$1 5 | if [ -z "$RELEASE_VERSION" ]; then 6 | echo "Usage: $0 " 7 | exit 1 8 | fi 9 | echo "Release version: $RELEASE_VERSION" 10 | 11 | # update version in main pom.xml 12 | sed -i "s|.*<\/clickhouse-java.version>|${RELEASE_VERSION}<\/clickhouse-java.version>|g" pom.xml 13 | 14 | # udpate examples with new version 15 | find ./examples/ -type f -name "pom.xml" -exec sed -i "s|.*<\/clickhouse-java.version>|${RELEASE_VERSION}-SNAPSHOT<\/clickhouse-java.version>|g" '{}' \; 16 | find ./examples/ -type f -name "gradle.properties" -exec sed -i "s|^ch_java_client_version=.*$|ch_java_client_version=${RELEASE_VERSION}|g" '{}' \; 17 | find ./performance/ -type f -name "pom.xml" -exec sed -i "s|.*<\/ch.jdbc.revision>|${RELEASE_VERSION}-SNAPSHOT<\/ch.jdbc.revision>|g" '{}' \; 18 | 19 | -------------------------------------------------------------------------------- /third-party-libraries/README.md: -------------------------------------------------------------------------------- 1 | # Repacked 3rd Party Libraries 2 | 3 | Repacked third party libraries(gRPC and RoaringBitmap) for JPMS support. 4 | 5 | ## Maven Dependencies 6 | 7 | ```xml 8 | 9 | com.clickhouse 10 | io.grpc 11 | 1.1.2 12 | 13 | 14 | com.clickhouse 15 | org.roaringbitmap 16 | 1.1.2 17 | 18 | ``` 19 | 20 | ## References 21 | 22 | - Enable MRJAR(multi-release jar) 23 | - Parent POM: https://github.com/meterware/multirelease-parent 24 | Note: another example https://github.com/apache/maven-compiler-plugin/blob/master/src/it/multirelease-patterns/singleproject-runtime/pom.xml#L102-L108 25 | - Basics: https://www.baeldung.com/java-multi-release-jar 26 | - Maven: https://maven.apache.org/plugins/maven-compiler-plugin/multirelease.html 27 | - Gradle: https://blog.gradle.org/mrjars 28 | - More to read at https://in.relation.to/2017/02/13/building-multi-release-jars-with-maven/ 29 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/LoadBalancerProvider.java: -------------------------------------------------------------------------------- 1 | package io.grpc; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class LoadBalancerProvider { 7 | /** 8 | * Default constructor. 9 | */ 10 | public LoadBalancerProvider() { 11 | // dummy constructor 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/ManagedChannelProvider.java: -------------------------------------------------------------------------------- 1 | package io.grpc; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class ManagedChannelProvider { 7 | /** 8 | * Default constructor. 9 | */ 10 | public ManagedChannelProvider() { 11 | // dummy constructor 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/NameResolverProvider.java: -------------------------------------------------------------------------------- 1 | package io.grpc; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class NameResolverProvider { 7 | /** 8 | * Default constructor. 9 | */ 10 | public NameResolverProvider() { 11 | // dummy constructor 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/ServerProvider.java: -------------------------------------------------------------------------------- 1 | package io.grpc; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class ServerProvider { 7 | /** 8 | * Default constructor. 9 | */ 10 | public ServerProvider() { 11 | // dummy constructor 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/netty/shaded/io/grpc/netty/DummyClass.java: -------------------------------------------------------------------------------- 1 | package io.grpc.netty.shaded.io.grpc.netty; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/netty/shaded/io/netty/channel/DummyClass.java: -------------------------------------------------------------------------------- 1 | package io.grpc.netty.shaded.io.netty.channel; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/netty/shaded/io/netty/handler/DummyClass.java: -------------------------------------------------------------------------------- 1 | package io.grpc.netty.shaded.io.netty.handler; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/netty/shaded/io/netty/handler/codec/DummyClass.java: -------------------------------------------------------------------------------- 1 | package io.grpc.netty.shaded.io.netty.handler.codec; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/netty/shaded/io/netty/handler/codec/http2/DummyClass.java: -------------------------------------------------------------------------------- 1 | package io.grpc.netty.shaded.io.netty.handler.codec.http2; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/netty/shaded/io/netty/handler/ssl/DummyClass.java: -------------------------------------------------------------------------------- 1 | package io.grpc.netty.shaded.io.netty.handler.ssl; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/io/grpc/netty/shaded/io/netty/handler/ssl/util/DummyClass.java: -------------------------------------------------------------------------------- 1 | package io.grpc.netty.shaded.io.netty.handler.ssl.util; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/io.grpc/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module io.grpc { 2 | exports io.grpc; 3 | // exports io.grpc.inprocess; 4 | // exports io.grpc.internal; 5 | // exports io.grpc.util; 6 | exports io.grpc.netty.shaded.io.grpc.netty; 7 | exports io.grpc.netty.shaded.io.netty.channel; 8 | exports io.grpc.netty.shaded.io.netty.handler; 9 | exports io.grpc.netty.shaded.io.netty.handler.codec; 10 | exports io.grpc.netty.shaded.io.netty.handler.codec.http2; 11 | exports io.grpc.netty.shaded.io.netty.handler.ssl; 12 | exports io.grpc.netty.shaded.io.netty.handler.ssl.util; 13 | 14 | requires java.logging; 15 | requires java.naming; 16 | // requires com.google.errorprone.annotations; 17 | // requires io.perfmark; 18 | 19 | uses io.grpc.ManagedChannelProvider; 20 | uses io.grpc.NameResolverProvider; 21 | uses io.grpc.ServerProvider; 22 | // uses io.grpc.internal.BinaryLogProvider; 23 | uses io.grpc.LoadBalancerProvider; 24 | } 25 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module org.apache.commons.compress { 2 | exports org.apache.commons.compress; 3 | exports org.apache.commons.compress.compressors; 4 | exports org.apache.commons.compress.compressors.bzip2; 5 | exports org.apache.commons.compress.compressors.deflate; 6 | exports org.apache.commons.compress.compressors.gzip; 7 | exports org.apache.commons.compress.compressors.lz4; 8 | exports org.apache.commons.compress.compressors.snappy; 9 | } 10 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/org/apache/commons/compress/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/org/apache/commons/compress/compressors/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress.compressors; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/org/apache/commons/compress/compressors/bzip2/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress.compressors.bzip2; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/org/apache/commons/compress/compressors/deflate/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress.compressors.deflate; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/org/apache/commons/compress/compressors/gzip/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress.compressors.gzip; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/org/apache/commons/compress/compressors/lz4/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress.compressors.lz4; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.apache.commons.compress/src/main/java/org/apache/commons/compress/compressors/snappy/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.apache.commons.compress.compressors.snappy; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.congocc/src/main/java/org/congocc/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.congocc; 2 | 3 | /** 4 | * Dummy class for generating sources and javadoc jars. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.roaringbitmap/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module org.roaringbitmap { 2 | exports org.roaringbitmap; 3 | exports org.roaringbitmap.buffer; 4 | exports org.roaringbitmap.longlong; 5 | } 6 | -------------------------------------------------------------------------------- /third-party-libraries/org.roaringbitmap/src/main/java/org/roaringbitmap/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.roaringbitmap; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.roaringbitmap/src/main/java/org/roaringbitmap/buffer/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.roaringbitmap.buffer; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /third-party-libraries/org.roaringbitmap/src/main/java/org/roaringbitmap/longlong/DummyClass.java: -------------------------------------------------------------------------------- 1 | package org.roaringbitmap.longlong; 2 | 3 | /** 4 | * Dummy class as placeholder. It will be removed during package phase. 5 | */ 6 | public class DummyClass { 7 | /** 8 | * Default constructor. 9 | */ 10 | public DummyClass() { 11 | } 12 | } 13 | --------------------------------------------------------------------------------