phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gr...@apache.org
Subject phoenix git commit: LP-1277 Support nulls in CHAR fields in CSV loader
Date Mon, 29 Jun 2015 06:34:28 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 047b8ca60 -> 987f7afbe


LP-1277 Support nulls in CHAR fields in CSV loader


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/987f7afb
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/987f7afb
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/987f7afb

Branch: refs/heads/4.x-HBase-1.0
Commit: 987f7afbea023fbddca12614f500d77ab1f69b31
Parents: 047b8ca
Author: Gabriel Reid <gabrielr@ngdata.com>
Authored: Thu Jun 25 21:36:51 2015 +0200
Committer: Gabriel Reid <gabrielr@ngdata.com>
Committed: Sun Jun 28 20:44:53 2015 +0200

----------------------------------------------------------------------
 .../phoenix/end2end/CSVCommonsLoaderIT.java       | 18 +++++++++++-------
 .../org/apache/phoenix/schema/types/PChar.java    |  3 ---
 .../phoenix/util/csv/CsvUpsertExecutor.java       |  5 ++++-
 3 files changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/987f7afb/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java
----------------------------------------------------------------------
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 d07ed8d..c7287ea 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
@@ -46,9 +46,10 @@ import org.junit.Test;
 public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT {
 
     private static final String DATATYPE_TABLE = "DATATYPE";
-    private static final String DATATYPES_CSV_VALUES = "CKEY, CVARCHAR, CINTEGER, CDECIMAL,
CUNSIGNED_INT, CBOOLEAN, CBIGINT, CUNSIGNED_LONG, CTIME, CDATE\n"
-            + "KEY1,A,2147483647,1.1,0,TRUE,9223372036854775807,0,1990-12-31 10:59:59,1999-12-31
23:59:59\n"
-            + "KEY2,B,-2147483648,-1.1,2147483647,FALSE,-9223372036854775808,9223372036854775807,2000-01-01
00:00:01,2012-02-29 23:59:59\n";
+    private static final String DATATYPES_CSV_VALUES = "CKEY, CVARCHAR, CCHAR, CINTEGER,
CDECIMAL, CUNSIGNED_INT, CBOOLEAN, CBIGINT, CUNSIGNED_LONG, CTIME, CDATE\n"
+            + "KEY1,A,A,2147483647,1.1,0,TRUE,9223372036854775807,0,1990-12-31 10:59:59,1999-12-31
23:59:59\n"
+            + "KEY2,B,B,-2147483648,-1.1,2147483647,FALSE,-9223372036854775808,9223372036854775807,2000-01-01
00:00:01,2012-02-29 23:59:59\n"
+            + "KEY3,,,,,,,,,,\n";
     private static final String STOCK_TABLE = "STOCK_SYMBOL";
     private static final String STOCK_TABLE_MULTI = "STOCK_SYMBOL_MULTI";
     private static final String STOCK_CSV_VALUES = "AAPL,APPLE Inc.\n"
@@ -480,7 +481,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT {
             String statements = "CREATE TABLE IF NOT EXISTS "
                     + DATATYPE_TABLE
                     + " (CKEY VARCHAR NOT NULL PRIMARY KEY,"
-                    + "  CVARCHAR VARCHAR, CINTEGER INTEGER, CDECIMAL DECIMAL(31,10), CUNSIGNED_INT
UNSIGNED_INT, CBOOLEAN BOOLEAN, CBIGINT BIGINT, CUNSIGNED_LONG UNSIGNED_LONG, CTIME TIME,
CDATE DATE);";
+                    + "  CVARCHAR VARCHAR, CCHAR CHAR(10), CINTEGER INTEGER, CDECIMAL DECIMAL(31,10),
CUNSIGNED_INT UNSIGNED_INT, CBOOLEAN BOOLEAN, CBIGINT BIGINT, CUNSIGNED_LONG UNSIGNED_LONG,
CTIME TIME, CDATE DATE);";
             conn = DriverManager.getConnection(getUrl())
                     .unwrap(PhoenixConnection.class);
             PhoenixRuntime.executeStatements(conn,
@@ -493,7 +494,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT {
 
             // Compare Phoenix ResultSet with CSV file content
             PreparedStatement statement = conn
-                    .prepareStatement("SELECT CKEY, CVARCHAR, CINTEGER, CDECIMAL, CUNSIGNED_INT,
CBOOLEAN, CBIGINT, CUNSIGNED_LONG, CTIME, CDATE FROM "
+                    .prepareStatement("SELECT CKEY, CVARCHAR, CCHAR, CINTEGER, CDECIMAL,
CUNSIGNED_INT, CBOOLEAN, CBIGINT, CUNSIGNED_LONG, CTIME, CDATE FROM "
                             + DATATYPE_TABLE);
             ResultSet phoenixResultSet = statement.executeQuery();
             parser = new CSVParser(new StringReader(DATATYPES_CSV_VALUES),
@@ -511,9 +512,12 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT {
                     i++;
                 }
                 // special case for matching date, time values
-                assertEquals(DateUtil.parseTime(record.get(8)),
+                String timeFieldValue = record.get(9);
+                assertEquals(timeFieldValue.isEmpty() ? null : DateUtil.parseTime(record.get(9)),
                         phoenixResultSet.getTime("CTIME"));
-                assertEquals(DateUtil.parseDate(record.get(9)),
+
+                String dateField = record.get(10);
+                assertEquals(dateField.isEmpty() ? null : DateUtil.parseDate(record.get(10)),
                         phoenixResultSet.getDate("CDATE"));
             }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/987f7afb/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
index c4d482c..c7cc1c1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PChar.java
@@ -174,9 +174,6 @@ public class PChar extends PDataType<String> {
 
     @Override
     public Object toObject(String value) {
-      if (value == null || value.length() == 0) {
-        throw newIllegalDataException(this + " may not be null");
-      }
       if (StringUtil.hasMultiByteChars(value)) {
         throw newIllegalDataException("CHAR types may only contain single byte characters
(" + value + ")");
       }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/987f7afb/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
index 0e3294b..156c3a4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/csv/CsvUpsertExecutor.java
@@ -233,7 +233,10 @@ public class CsvUpsertExecutor implements Closeable {
         @Nullable
         @Override
         public Object apply(@Nullable String input) {
-            if(dateTimeParser != null) {
+            if (input == null || input.isEmpty()) {
+                return null;
+            }
+            if (dateTimeParser != null) {
                 long epochTime = dateTimeParser.parseDateTime(input);
                 byte[] byteValue = new byte[dataType.getByteSize()];
                 dataType.getCodec().encodeLong(epochTime, byteValue, 0);


Mime
View raw message