METAMODEL-1151: Added DataContextFactory update for CSV

Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/689f9d9c
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/689f9d9c
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/689f9d9c

Branch: refs/heads/master
Commit: 689f9d9c0614e9c402640bb410c0ccb69b27329e
Parents: b4814d1
Author: Kasper Sørensen <i.am.kasper.soren...@gmail.com>
Authored: Sat Aug 5 22:52:52 2017 -0700
Committer: Kasper Sørensen <i.am.kasper.soren...@gmail.com>
Committed: Sat Aug 5 22:52:52 2017 -0700

----------------------------------------------------------------------
 .../apache/metamodel/csv/CsvDataContextFactory.java | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metamodel/blob/689f9d9c/csv/src/main/java/org/apache/metamodel/csv/CsvDataContextFactory.java
----------------------------------------------------------------------
diff --git 
a/csv/src/main/java/org/apache/metamodel/csv/CsvDataContextFactory.java 
b/csv/src/main/java/org/apache/metamodel/csv/CsvDataContextFactory.java
index 105fd5b..eeaad1b 100644
--- a/csv/src/main/java/org/apache/metamodel/csv/CsvDataContextFactory.java
+++ b/csv/src/main/java/org/apache/metamodel/csv/CsvDataContextFactory.java
@@ -22,8 +22,11 @@ import org.apache.metamodel.DataContext;
 import org.apache.metamodel.factory.DataContextFactory;
 import org.apache.metamodel.factory.DataContextProperties;
 import org.apache.metamodel.factory.ResourceFactoryRegistry;
+import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
+import org.apache.metamodel.schema.naming.CustomColumnNamingStrategy;
 import org.apache.metamodel.util.FileHelper;
 import org.apache.metamodel.util.Resource;
+import org.apache.metamodel.util.SimpleTableDef;
 
 public class CsvDataContextFactory implements DataContextFactory {
 
@@ -49,8 +52,17 @@ public class CsvDataContextFactory implements 
DataContextFactory {
         final boolean failOnInconsistentRowLength = 
getBoolean(properties.isFailOnInconsistentRowLength(), false);
         final boolean multilineValuesEnabled = 
getBoolean(properties.isMultilineValuesEnabled(), true);
 
-        final CsvConfiguration configuration = new 
CsvConfiguration(columnNameLineNumber, encoding, separatorChar,
-                quoteChar, escapeChar, failOnInconsistentRowLength, 
multilineValuesEnabled);
+        final ColumnNamingStrategy columnNamingStrategy;
+        if (properties.getTableDefs() == null) {
+            columnNamingStrategy = null;
+        } else {
+            final SimpleTableDef firstTable = properties.getTableDefs()[0];
+            final String[] columnNames = firstTable.getColumnNames();
+            columnNamingStrategy = new CustomColumnNamingStrategy(columnNames);
+        }
+
+        final CsvConfiguration configuration = new 
CsvConfiguration(columnNameLineNumber, columnNamingStrategy,
+                encoding, separatorChar, quoteChar, escapeChar, 
failOnInconsistentRowLength, multilineValuesEnabled);
         return new CsvDataContext(resource, configuration);
     }
 

Reply via email to