未验证 提交 b5a28d8e 编写于 作者: J Jaromir Hamala 提交者: GitHub

fix(pgwire) Rudimentary support for COPY FROM via pgwire (#2061)

上级 c57a50b3
......@@ -1844,7 +1844,6 @@ public class PGConnectionContext implements IOContext, Mutable, WriterSource {
case CompiledQuery.COPY_LOCAL:
// uncached
queryTag = TAG_COPY;
sendCopyInResponse(compiler.getEngine(), cq.getTextLoader());
break;
case CompiledQuery.SET:
queryTag = TAG_SET;
......@@ -2213,6 +2212,9 @@ public class PGConnectionContext implements IOContext, Mutable, WriterSource {
responseAsciiSink.reset();
}
// This method is currently unused. it's used for the COPY sub-protocol, which is currently not implemented.
// It's left here so when we add the sub-protocol later we won't need to reimplemented it.
// We could keep it just in git history, but chances are nobody would recall to search for it there
private void sendCopyInResponse(CairoEngine engine, TextLoader textLoader) throws PeerDisconnectedException, PeerIsSlowToReadException {
if (
TableUtils.TABLE_EXISTS == engine.getStatus(
......
......@@ -62,6 +62,7 @@ import org.postgresql.core.BaseConnection;
import org.postgresql.util.PGTimestamp;
import org.postgresql.util.PSQLException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Date;
......@@ -93,6 +94,7 @@ public class PGJobContextTest extends BasePGTest {
@BeforeClass
public static void init() {
inputRoot = new File(".").getAbsolutePath();
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.0'");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
final Stream<Object[]> dates = LongStream.rangeClosed(0, count - 1)
......@@ -1679,6 +1681,25 @@ public class PGJobContextTest extends BasePGTest {
}
}
@Test
public void testLocalCopyFrom() throws Exception {
try (final PGWireServer ignored = createPGServer(2);
final Connection connection = getConnection(false, true);
final PreparedStatement copyStatement = connection.prepareStatement("copy testLocalCopyFrom from '/src/test/resources/csv/test-numeric-headers.csv' with header true")) {
copyStatement.execute();
try (final PreparedStatement selectStatement = connection.prepareStatement("select * FROM testLocalCopyFrom");
final ResultSet rs = selectStatement.executeQuery()) {
sink.clear();
assertResultSet("type[VARCHAR],value[VARCHAR],active[VARCHAR],desc[VARCHAR],_1[INTEGER]\n"
+ "ABC,xy,a,brown fox jumped over the fence,10\n"
+ "CDE,bb,b,sentence 1\n"
+ "sentence 2,12\n", sink, rs);
}
}
}
@Test
public void testCursorFetch() throws Exception {
assertMemoryLeak(() -> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册