1
1
package ru .yandex .clickhouse ;
2
2
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 ;
9
6
10
7
import java .io .File ;
11
8
import java .io .FileInputStream ;
12
9
import java .io .IOException ;
13
10
import java .io .InputStream ;
14
11
import java .sql .SQLException ;
12
+ import java .util .Objects ;
15
13
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 ;
19
21
20
22
public class Writer extends ConfigurableApi <Writer > {
21
23
@@ -27,10 +29,12 @@ public class Writer extends ConfigurableApi<Writer> {
27
29
28
30
Writer (ClickHouseStatementImpl statement ) {
29
31
super (statement );
32
+
33
+ dataCompression (ClickHouseCompression .none );
30
34
}
31
35
32
36
/**
33
- * Specifies format for further insert of data via send()
37
+ * Specifies format for further insert of data via send().
34
38
*
35
39
* @param format
36
40
* the format of the data to upload
@@ -45,7 +49,7 @@ public Writer format(ClickHouseFormat format) {
45
49
}
46
50
47
51
/**
48
- * Set table name for data insertion
52
+ * Set table name for data insertion.
49
53
*
50
54
* @param table
51
55
* name of the table to upload the data to
@@ -58,7 +62,7 @@ public Writer table(String table) {
58
62
}
59
63
60
64
/**
61
- * Set SQL for data insertion
65
+ * Set SQL for data insertion.
62
66
*
63
67
* @param sql
64
68
* in a form "INSERT INTO table_name [(X,Y,Z)] VALUES "
@@ -71,7 +75,7 @@ public Writer sql(String sql) {
71
75
}
72
76
73
77
/**
74
- * Specifies data input stream
78
+ * Specifies data input stream.
75
79
*
76
80
* @param stream
77
81
* a stream providing the data to upload
@@ -83,7 +87,7 @@ public Writer data(InputStream stream) {
83
87
}
84
88
85
89
/**
86
- * Specifies data input stream, and the format to use
90
+ * Specifies data input stream, and the format to use.
87
91
*
88
92
* @param stream
89
93
* a stream providing the data to upload
@@ -96,7 +100,7 @@ public Writer data(InputStream stream, ClickHouseFormat format) {
96
100
}
97
101
98
102
/**
99
- * Shortcut method for specifying a file as an input
103
+ * Shortcut method for specifying a file as an input.
100
104
*
101
105
* @param input
102
106
* the file to upload
@@ -116,10 +120,9 @@ public Writer data(File input, ClickHouseFormat format, ClickHouseCompression co
116
120
}
117
121
118
122
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
+
123
126
return this ;
124
127
}
125
128
@@ -128,7 +131,7 @@ public Writer data(File input, ClickHouseFormat format) {
128
131
}
129
132
130
133
/**
131
- * Method to call, when Writer is fully configured
134
+ * Method to call, when Writer is fully configured.
132
135
*/
133
136
public void send () throws SQLException {
134
137
HttpEntity entity ;
@@ -149,7 +152,7 @@ private void send(HttpEntity entity) throws SQLException {
149
152
}
150
153
151
154
/**
152
- * Allows to send stream of data to ClickHouse
155
+ * Allows to send stream of data to ClickHouse.
153
156
*
154
157
* @param sql
155
158
* 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
165
168
}
166
169
167
170
/**
168
- * Convenient method for importing the data into table
171
+ * Convenient method for importing the data into table.
169
172
*
170
173
* @param table
171
174
* table name
@@ -182,7 +185,7 @@ public void sendToTable(String table, InputStream data, ClickHouseFormat format)
182
185
183
186
/**
184
187
* Sends the data in {@link ClickHouseFormat#RowBinary RowBinary} or in
185
- * {@link ClickHouseFormat#Native Native} format
188
+ * {@link ClickHouseFormat#Native Native} format.
186
189
*
187
190
* @param sql
188
191
* the SQL statement to execute
0 commit comments