Skip to content

Commit 0bc6d8e

Browse files
authored
Merge pull request #579 from den-crane/test/ext_data
test for large external data
2 parents c4fe4d0 + af97634 commit 0bc6d8e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/test/java/ru/yandex/clickhouse/integration/ClickHouseStatementImplTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package ru.yandex.clickhouse.integration;
22

33
import java.io.ByteArrayInputStream;
4+
import java.io.InputStream;
45
import java.io.UnsupportedEncodingException;
56
import java.math.BigInteger;
7+
import java.nio.charset.Charset;
68
import java.sql.Array;
79
import java.sql.Connection;
810
import java.sql.ResultSet;
@@ -146,6 +148,59 @@ public void testExternalData() throws SQLException, UnsupportedEncodingException
146148
Assert.assertEquals(groupName, "Group");
147149
}
148150

151+
152+
private InputStream getTSVStream(final int rowsCount) {
153+
return new InputStream() {
154+
private int si = 0;
155+
private String s = "";
156+
private int i = 0;
157+
158+
private boolean genNextString() {
159+
if (i >= rowsCount) return false;
160+
si = 0;
161+
s = String.format("%d\t%d\n", i, i);
162+
i++;
163+
return true;
164+
}
165+
166+
public int read() {
167+
if (si >= s.length()) {
168+
if ( ! genNextString() ) {
169+
return -1;
170+
}
171+
}
172+
return s.charAt( si++ );
173+
}
174+
};
175+
}
176+
177+
178+
@Test
179+
public void testExternalDataStream() throws SQLException, UnsupportedEncodingException {
180+
final ClickHouseStatement statement = connection.createStatement();
181+
connection.createStatement().execute("DROP TABLE IF EXISTS test.testExternalData");
182+
connection.createStatement().execute("CREATE TABLE test.testExternalData (id UInt64, s String) ENGINE = Memory");
183+
connection.createStatement().execute("insert into test.testExternalData select number, toString(number) from numbers(500,100000)");
184+
185+
InputStream inputStream = getTSVStream(100000);
186+
187+
ClickHouseExternalData extData = new ClickHouseExternalData("ext_data", inputStream);
188+
extData.setStructure("id UInt64, s String");
189+
190+
ResultSet rs = connection.createStatement().executeQuery(
191+
"select count() cnt from test.testExternalData where (id,s) in ext_data",
192+
null,
193+
Collections.singletonList(extData)
194+
);
195+
196+
rs.next();
197+
198+
int cnt = rs.getInt("cnt");
199+
200+
Assert.assertEquals(cnt, 99500);
201+
}
202+
203+
149204
@Test
150205
public void testResultSetWithExtremes() throws SQLException {
151206
ClickHouseProperties properties = new ClickHouseProperties();

0 commit comments

Comments
 (0)