提交 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 { ...@@ -1019,11 +1019,15 @@ public class Parser {
read(")"); read(")");
table = new RangeTable(mainSchema, min, max, false); table = new RangeTable(mainSchema, min, max, false);
} else { } else {
Expression func = readFunction(schema, tableName); Expression expr = readFunction(schema, tableName);
if (!(func instanceof FunctionCall)) { if (!(expr instanceof FunctionCall)) {
throw getSyntaxError(); 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)) { } else if (equalsToken("DUAL", tableName)) {
table = getDualTable(false); table = getDualTable(false);
......
...@@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream; ...@@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.sql.Connection; import java.sql.Connection;
...@@ -53,6 +54,7 @@ public class TestCsv extends TestBase { ...@@ -53,6 +54,7 @@ public class TestCsv extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
testChangeData();
testOptions(); testOptions();
testPseudoBom(); testPseudoBom();
testWriteRead(); testWriteRead();
...@@ -68,6 +70,27 @@ public class TestCsv extends TestBase { ...@@ -68,6 +70,27 @@ public class TestCsv extends TestBase {
deleteDb("csv"); 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() { private void testOptions() {
Csv csv = Csv.getInstance(); Csv csv = Csv.getInstance();
assertEquals(",", csv.getFieldSeparatorWrite()); assertEquals(",", csv.getFieldSeparatorWrite());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论