11package ru .yandex .clickhouse ;
22
3- import org .apache .http .HttpEntity ;
4- import org .apache .http .entity .InputStreamEntity ;
5- import ru .yandex .clickhouse .domain .ClickHouseCompression ;
6- import ru .yandex .clickhouse .domain .ClickHouseFormat ;
7- import ru .yandex .clickhouse .util .ClickHouseStreamCallback ;
8- import ru .yandex .clickhouse .util .ClickHouseStreamHttpEntity ;
3+ import static ru .yandex .clickhouse .domain .ClickHouseFormat .Native ;
4+ import static ru .yandex .clickhouse .domain .ClickHouseFormat .RowBinary ;
5+ import static ru .yandex .clickhouse .domain .ClickHouseFormat .TabSeparated ;
96
107import java .io .File ;
118import java .io .FileInputStream ;
129import java .io .IOException ;
1310import java .io .InputStream ;
1411import java .sql .SQLException ;
12+ import java .util .Objects ;
1513
16- import static ru .yandex .clickhouse .domain .ClickHouseFormat .Native ;
17- import static ru .yandex .clickhouse .domain .ClickHouseFormat .RowBinary ;
18- import static ru .yandex .clickhouse .domain .ClickHouseFormat .TabSeparated ;
14+ import org .apache .http .HttpEntity ;
15+ import org .apache .http .entity .InputStreamEntity ;
16+ import ru .yandex .clickhouse .domain .ClickHouseCompression ;
17+ import ru .yandex .clickhouse .domain .ClickHouseFormat ;
18+ import ru .yandex .clickhouse .settings .ClickHouseQueryParam ;
19+ import ru .yandex .clickhouse .util .ClickHouseStreamCallback ;
20+ import ru .yandex .clickhouse .util .ClickHouseStreamHttpEntity ;
1921
2022public class Writer extends ConfigurableApi <Writer > {
2123
@@ -27,10 +29,12 @@ public class Writer extends ConfigurableApi<Writer> {
2729
2830 Writer (ClickHouseStatementImpl statement ) {
2931 super (statement );
32+
33+ dataCompression (ClickHouseCompression .none );
3034 }
3135
3236 /**
33- * Specifies format for further insert of data via send()
37+ * Specifies format for further insert of data via send().
3438 *
3539 * @param format
3640 * the format of the data to upload
@@ -45,7 +49,7 @@ public Writer format(ClickHouseFormat format) {
4549 }
4650
4751 /**
48- * Set table name for data insertion
52+ * Set table name for data insertion.
4953 *
5054 * @param table
5155 * name of the table to upload the data to
@@ -58,7 +62,7 @@ public Writer table(String table) {
5862 }
5963
6064 /**
61- * Set SQL for data insertion
65+ * Set SQL for data insertion.
6266 *
6367 * @param sql
6468 * in a form "INSERT INTO table_name [(X,Y,Z)] VALUES "
@@ -71,7 +75,7 @@ public Writer sql(String sql) {
7175 }
7276
7377 /**
74- * Specifies data input stream
78+ * Specifies data input stream.
7579 *
7680 * @param stream
7781 * a stream providing the data to upload
@@ -83,7 +87,7 @@ public Writer data(InputStream stream) {
8387 }
8488
8589 /**
86- * Specifies data input stream, and the format to use
90+ * Specifies data input stream, and the format to use.
8791 *
8892 * @param stream
8993 * a stream providing the data to upload
@@ -96,7 +100,7 @@ public Writer data(InputStream stream, ClickHouseFormat format) {
96100 }
97101
98102 /**
99- * Shortcut method for specifying a file as an input
103+ * Shortcut method for specifying a file as an input.
100104 *
101105 * @param input
102106 * the file to upload
@@ -116,10 +120,9 @@ public Writer data(File input, ClickHouseFormat format, ClickHouseCompression co
116120 }
117121
118122 public Writer dataCompression (ClickHouseCompression compression ) {
119- if (null == compression ) {
120- throw new NullPointerException ("Compression can not be null" );
121- }
122- this .compression = compression ;
123+ this .compression = Objects .requireNonNull (compression , "Compression can not be null" );
124+ this .addDbParam (ClickHouseQueryParam .COMPRESS , String .valueOf (compression != ClickHouseCompression .none ));
125+
123126 return this ;
124127 }
125128
@@ -128,7 +131,7 @@ public Writer data(File input, ClickHouseFormat format) {
128131 }
129132
130133 /**
131- * Method to call, when Writer is fully configured
134+ * Method to call, when Writer is fully configured.
132135 */
133136 public void send () throws SQLException {
134137 HttpEntity entity ;
@@ -149,7 +152,7 @@ private void send(HttpEntity entity) throws SQLException {
149152 }
150153
151154 /**
152- * Allows to send stream of data to ClickHouse
155+ * Allows to send stream of data to ClickHouse.
153156 *
154157 * @param sql
155158 * in a form of "INSERT INTO table_name (X,Y,Z) VALUES "
@@ -165,7 +168,7 @@ public void send(String sql, InputStream data, ClickHouseFormat format) throws S
165168 }
166169
167170 /**
168- * Convenient method for importing the data into table
171+ * Convenient method for importing the data into table.
169172 *
170173 * @param table
171174 * table name
@@ -182,7 +185,7 @@ public void sendToTable(String table, InputStream data, ClickHouseFormat format)
182185
183186 /**
184187 * Sends the data in {@link ClickHouseFormat#RowBinary RowBinary} or in
185- * {@link ClickHouseFormat#Native Native} format
188+ * {@link ClickHouseFormat#Native Native} format.
186189 *
187190 * @param sql
188191 * the SQL statement to execute
0 commit comments