As per #208: Fix PostgreSQL native type being null
authorlixiaobao <lixiaobao0202@gmail.com>
Tue, 29 Jan 2019 21:37:29 +0000 (13:37 -0800)
committerKasper Sørensen <ksorensen@satorisoftware.com>
Tue, 29 Jan 2019 21:37:29 +0000 (13:37 -0800)
jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java

index 7fe03cb..b582930 100644 (file)
@@ -47,14 +47,16 @@ public class PostgresqlQueryRewriter extends LimitOffsetQueryRewriter {
 
     @Override
     public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize) {
-        switch (nativeType) {
-        case "bool":
-            // override the normal behaviour of postgresql which maps "bool" to
-            // a BIT.
-            return ColumnType.BOOLEAN;
-        case "json":
-        case "jsonb":
-            return ColumnType.MAP;
+        if (nativeType != null) {
+            switch (nativeType) {
+            case "bool":
+                // override the normal behaviour of postgresql which maps "bool" to
+                // a BIT.
+                return ColumnType.BOOLEAN;
+            case "json":
+            case "jsonb":
+                return ColumnType.MAP;
+            }
         }
         return super.getColumnType(jdbcType, nativeType, columnSize);
     }
@@ -106,18 +108,20 @@ public class PostgresqlQueryRewriter extends LimitOffsetQueryRewriter {
 
     @Override
     public Object getResultSetValue(ResultSet resultSet, int columnIndex, Column column) throws SQLException {
-        switch (column.getNativeType()) {
-        case "json":
-        case "jsonb":
-            assert column.getType() == ColumnType.MAP;
-            final String stringValue = resultSet.getString(columnIndex);
-            if (stringValue == null) {
-                return null;
-            }
-            try {
-                return jsonObjectMapper.readValue(stringValue, Map.class);
-            } catch (Exception e) {
-                throw new IllegalArgumentException("Unable to read string as JSON: " + stringValue);
+        if (column.getNativeType() != null) {
+            switch (column.getNativeType()) {
+            case "json":
+            case "jsonb":
+                assert column.getType() == ColumnType.MAP;
+                final String stringValue = resultSet.getString(columnIndex);
+                if (stringValue == null) {
+                    return null;
+                }
+                try {
+                    return jsonObjectMapper.readValue(stringValue, Map.class);
+                } catch (Exception e) {
+                    throw new IllegalArgumentException("Unable to read string as JSON: " + stringValue);
+                }
             }
         }
         return super.getResultSetValue(resultSet, columnIndex, column);