提交 90819f31 authored 作者: Thomas Mueller's avatar Thomas Mueller

Executing a CSVREAD query multiple times could result in an exception if the…

Executing a CSVREAD query multiple times could result in an exception if the data was changed on disk.
上级 19ca69aa
......@@ -1019,11 +1019,15 @@ public class Parser {
read(")");
table = new RangeTable(mainSchema, min, max, false);
} else {
Expression func = readFunction(schema, tableName);
if (!(func instanceof FunctionCall)) {
Expression expr = readFunction(schema, tableName);
if (!(expr instanceof FunctionCall)) {
throw getSyntaxError();
}
table = new FunctionTable(mainSchema, session, func, (FunctionCall) func);
FunctionCall call = (FunctionCall) expr;
if (!call.isDeterministic()) {
recompileAlways = true;
}
table = new FunctionTable(mainSchema, session, expr, call);
}
} else if (equalsToken("DUAL", tableName)) {
table = getDualTable(false);
......
......@@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringReader;
import java.sql.Connection;
......@@ -53,6 +54,7 @@ public class TestCsv extends TestBase {
}
public void test() throws Exception {
testChangeData();
testOptions();
testPseudoBom();
testWriteRead();
......@@ -68,6 +70,27 @@ public class TestCsv extends TestBase {
deleteDb("csv");
}
private void testChangeData() throws Exception {
OutputStream out = IOUtils.openFileOutputStream(getBaseDir()+"/test.tsv", false);
out.write("a,b,c,d,e,f,g\n1".getBytes());
out.close();
Connection conn = getConnection("csv");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from csvread('"+getBaseDir()+"/test.tsv')");
assertEquals(7, rs.getMetaData().getColumnCount());
assertEquals("A", rs.getMetaData().getColumnLabel(1));
rs.next();
assertEquals(1, rs.getInt(1));
out = IOUtils.openFileOutputStream(getBaseDir()+"/test.tsv", false);
out.write("x".getBytes());
out.close();
rs = stat.executeQuery("select * from csvread('"+getBaseDir()+"/test.tsv')");
assertEquals(1, rs.getMetaData().getColumnCount());
assertEquals("X", rs.getMetaData().getColumnLabel(1));
assertFalse(rs.next());
conn.close();
}
private void testOptions() {
Csv csv = Csv.getInstance();
assertEquals(",", csv.getFieldSeparatorWrite());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论