You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by an...@apache.org on 2019/10/07 18:17:43 UTC

[phoenix] branch master updated: PHOENIX-5506 Psql load fails with lower table name

This is an automated email from the ASF dual-hosted git repository.

ankit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new 7d0e2f8  PHOENIX-5506 Psql load fails with lower table name
7d0e2f8 is described below

commit 7d0e2f88b6e830a200d074eb167aeb2d2368e6c5
Author: Ankit Singhal <an...@apache.org>
AuthorDate: Mon Oct 7 11:17:29 2019 -0700

    PHOENIX-5506 Psql load fails with lower table name
---
 .../apache/phoenix/end2end/CSVCommonsLoaderIT.java | 35 ++++++++++++++++++++++
 .../org/apache/phoenix/util/CSVCommonsLoader.java  |  3 +-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
index 9b5581d..8db7afd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
@@ -23,7 +23,9 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.File;
 import java.io.StringReader;
+import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -35,6 +37,7 @@ import java.util.Properties;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
+import org.apache.commons.io.FileUtils;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixTestDriver;
 import org.apache.phoenix.schema.IllegalDataException;
@@ -43,7 +46,9 @@ import org.apache.phoenix.schema.types.PArrayDataType;
 import org.apache.phoenix.util.CSVCommonsLoader;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 
 public class CSVCommonsLoaderIT extends ParallelStatsDisabledIT {
 
@@ -98,6 +103,8 @@ public class CSVCommonsLoaderIT extends ParallelStatsDisabledIT {
             + "\n"
             + CSV_VALUES_BAD_ENCAPSULATED_CONTROL_CHARS;
 
+    @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
+
     @Test
     public void testCSVCommonsUpsert() throws Exception {
         CSVParser parser = null;
@@ -766,4 +773,32 @@ public class CSVCommonsLoaderIT extends ParallelStatsDisabledIT {
         }
 
     }
+
+    @Test public void testLowerCaseTable() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        conn.setAutoCommit(true);
+        String tableName = generateUniqueName().toLowerCase();
+        String t1 = generateUniqueName();
+        String t2 = t1 + generateUniqueName();
+        String csvFileName = "test.csv";
+        conn.createStatement().execute("CREATE TABLE \"" + tableName
+            + "\" (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2))");
+        File tempFile = tempFolder.newFile(csvFileName);
+        FileUtils.writeStringToFile(tempFile, "'" + t1 + "','x'");
+        try {
+            CSVCommonsLoader csvLoader =
+                new CSVCommonsLoader(conn.unwrap(PhoenixConnection.class), "" + tableName + "",
+                    null, false, ',', '"', '\\', null);
+            csvLoader.upsert(tempFile.getAbsolutePath());
+        } catch (Exception e) {
+            fail("Failed with Exception:" + e.getMessage());
+        }
+        ResultSet rs =
+            conn.createStatement().executeQuery("SELECT * FROM \"" + tableName + "\" order by k2");
+        assertTrue(rs.next());
+        assertEquals("'"+t1+"'",rs.getString(1));
+        assertEquals("'"+"x"+"'",rs.getString(2));
+        assertFalse(rs.next());
+
+    }
 }
\ No newline at end of file
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
index 59ed9cf..4ade283 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
@@ -207,7 +207,8 @@ public class CSVCommonsLoader {
             long start = System.currentTimeMillis();
             CsvUpsertListener upsertListener = new CsvUpsertListener(conn,
                     conn.getMutateBatchSize(), isStrict);
-            CsvUpsertExecutor csvUpsertExecutor = new CsvUpsertExecutor(conn, tableName,
+            CsvUpsertExecutor csvUpsertExecutor = new CsvUpsertExecutor(conn,
+                SchemaUtil.getEscapedFullTableName(tableName),
                     columnInfoList, upsertListener, arrayElementSeparator);
 
             csvUpsertExecutor.execute(csvParser);