METAMODEL-1113: Fixed
authorArjan Seijkens <Arjan.Seijkens@humaninference.com>
Tue, 6 Sep 2016 04:11:40 +0000 (21:11 -0700)
committerKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Tue, 6 Sep 2016 04:12:35 +0000 (21:12 -0700)
Fixes #125

CHANGES.md
csv/src/main/java/org/apache/metamodel/csv/CsvConfiguration.java
csv/src/test/java/org/apache/metamodel/csv/CsvDataContextTest.java
excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java

index 0c06db2..c8f288f 100644 (file)
@@ -3,6 +3,7 @@
  * [METAMODEL-1111] - Added WHERE rewrite for Oracle when empty strings are considered as NULL.
  * [METAMODEL-1109] - Fixed diacritics/encoding issue with Fixed Width reader.
  * [METAMODEL-1115] - Added support for passing your own PartnerConnection object to the Salesforce.com connector.
+ * [METAMODEL-1113] - Fixed support for ColumnNamingStrategy in CSV connector.
 
 ### Apache MetaModel 4.5.4
 
index abcf2d4..332ef4b 100644 (file)
@@ -94,7 +94,7 @@ public final class CsvConfiguration extends BaseObject implements Serializable {
         this.escapeChar = escapeChar;
         this.failOnInconsistentRowLength = failOnInconsistentRowLength;
         this.multilineValues = multilineValues;
-        this.columnNamingStrategy = null;
+        this.columnNamingStrategy = columnNamingStrategy;
     }
     
     /**
index e417cf6..39f9d43 100644 (file)
@@ -48,6 +48,7 @@ import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.MutableColumn;
 import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.naming.CustomColumnNamingStrategy;
 import org.apache.metamodel.util.FileHelper;
 import org.apache.metamodel.util.MutableRef;
 
@@ -828,4 +829,26 @@ public class CsvDataContextTest extends TestCase {
     // e.getMessage());
     // }
     // }
+
+    public void testCustomColumnNames() throws Exception {
+        final String firstColumnName = "first";
+        final String secondColumnName = "second";
+        final String thirdColumnName = "third";
+        final String fourthColumnName = "fourth";
+
+        final CsvConfiguration configuration = new CsvConfiguration(CsvConfiguration.DEFAULT_COLUMN_NAME_LINE,
+                new CustomColumnNamingStrategy(firstColumnName, secondColumnName, thirdColumnName, fourthColumnName),
+                FileHelper.DEFAULT_ENCODING, CsvConfiguration.DEFAULT_SEPARATOR_CHAR,
+                CsvConfiguration.DEFAULT_QUOTE_CHAR, CsvConfiguration.DEFAULT_ESCAPE_CHAR, false, true);
+
+        final DataContext dataContext = new CsvDataContext(new File("src/test/resources/csv_people.csv"),
+                configuration);
+
+        final Table table = dataContext.getDefaultSchema().getTable(0);
+
+        assertNotNull(table.getColumnByName(firstColumnName));
+        assertNotNull(table.getColumnByName(secondColumnName));
+        assertNotNull(table.getColumnByName(thirdColumnName));
+        assertNotNull(table.getColumnByName(fourthColumnName));
+    }
 }
\ No newline at end of file
index 3b69290..f8406c3 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.metamodel.query.Query;
 import org.apache.metamodel.schema.Column;
 import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.naming.CustomColumnNamingStrategy;
 import org.apache.metamodel.util.DateUtils;
 import org.apache.metamodel.util.FileHelper;
 import org.apache.metamodel.util.Month;
@@ -775,4 +776,20 @@ public class ExcelDataContextTest extends TestCase {
         assertNotNull(ds);
         ds.close();
     }
+
+    public void testCustomColumnNames() throws Exception {
+        final String firstColumnName = "first";
+        final String secondColumnName = "second";
+        final String thirdColumnName = "third";
+
+        final ExcelConfiguration configuration = new ExcelConfiguration(ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE,
+                new CustomColumnNamingStrategy(firstColumnName, secondColumnName, thirdColumnName), true, false);
+        final DataContext dataContext = new ExcelDataContext(copyOf("src/test/resources/Spreadsheet2007.xlsx"),
+                configuration);
+        final Table table = dataContext.getDefaultSchema().getTable(0);
+
+        assertNotNull(table.getColumnByName(firstColumnName));
+        assertNotNull(table.getColumnByName(secondColumnName));
+        assertNotNull(table.getColumnByName(thirdColumnName));
+    }
 }
\ No newline at end of file
index 7962cf6..7a4b75f 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.query.Query;
 import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.naming.CustomColumnNamingStrategy;
 
 public class FixedWidthDataContextTest extends TestCase {
 
@@ -221,4 +222,20 @@ public class FixedWidthDataContextTest extends TestCase {
         assertEquals("[3, howdy, partner]", Arrays.toString(ds.getRow().getValues()));
         assertFalse(ds.next());
     }
+
+    public void testCustomColumnNames() throws Exception {
+        final String firstColumnName = "first";
+        final String secondColumnName = "second";
+
+        final FixedWidthConfiguration configuration = new FixedWidthConfiguration(
+                FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, new CustomColumnNamingStrategy(firstColumnName,
+                        secondColumnName), "UTF8", new int[] { 10, 10 }, true);
+
+        final DataContext dataContext = new FixedWidthDataContext(new File("src/test/resources/example_simple1.txt"),
+                configuration);
+        final Table table = dataContext.getDefaultSchema().getTable(0);
+
+        assertNotNull(table.getColumnByName(firstColumnName));
+        assertNotNull(table.getColumnByName(secondColumnName));
+    }
 }