You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ar...@apache.org on 2019/12/12 09:32:32 UTC
[metamodel] branch master updated (2f3f0d7 -> b8d193a)
This is an automated email from the ASF dual-hosted git repository.
arjansh pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/metamodel.git.
from 2f3f0d7 MM-82 Detect Column Types - Refactoring based on comments in PR 5
new 740fa13 METAMODEL-82 - Fix integers in double columns
new b8d193a MM-82 Detect Column Types - Update CHANGES.md
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
CHANGES.md | 1 +
.../org/apache/metamodel/excel/ExcelUtils.java | 24 +++++++++++-----------
.../metamodel/excel/ExcelDataContextTest.java | 10 ++++++---
3 files changed, 20 insertions(+), 15 deletions(-)
[metamodel] 02/02: MM-82 Detect Column Types - Update CHANGES.md
Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
arjansh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metamodel.git
commit b8d193a46a89e45f649e4f8e436cd17e90d52204
Author: Gerard Dellemann <g....@quadient.com>
AuthorDate: Thu Dec 12 09:14:07 2019 +0100
MM-82 Detect Column Types - Update CHANGES.md
---
CHANGES.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGES.md b/CHANGES.md
index 730def9..2ab7c90 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,4 +1,5 @@
### Apache MetaModel _WIP_
+ * [METAMODEL-82] - Detect Column Types with Excel datastores
* [METAMODEL-1221] - Upgrade to Elasticsearch 7.3
* Bind Travis build to Trusty distribution to avoid CI build failures.
[metamodel] 01/02: METAMODEL-82 - Fix integers in double columns
Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
arjansh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metamodel.git
commit 740fa138ec06bb769fe9a2ac0c7c6a33f92dfdff
Author: Gerard Dellemann <g....@quadient.com>
AuthorDate: Wed Dec 11 15:58:55 2019 +0100
METAMODEL-82 - Fix integers in double columns
---
.../org/apache/metamodel/excel/ExcelUtils.java | 24 +++++++++++-----------
.../metamodel/excel/ExcelDataContextTest.java | 10 ++++++---
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
index 21491ec..ce66480 100644
--- a/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
+++ b/excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
@@ -275,20 +275,20 @@ final class ExcelUtils {
private static Object evaluateCell(final Workbook workbook, final Cell cell, final ColumnType expectedColumnType) {
final Object value = getCellValueAsObject(workbook, cell);
- if (value == null || value.getClass().equals(expectedColumnType.getJavaEquivalentClass())) {
+ if (value == null || value.getClass().equals(expectedColumnType.getJavaEquivalentClass()) || (value
+ .getClass()
+ .equals(Integer.class) && expectedColumnType.getJavaEquivalentClass().equals(Double.class))) {
return value;
+ } else {
+ if (logger.isWarnEnabled()) {
+ logger
+ .warn("Cell ({},{}) has the value '{}' of data type '{}', which doesn't match the detected "
+ + "column's data type '{}'. This cell gets value NULL in the DataSet.", cell
+ .getRowIndex(), cell.getColumnIndex(), value, value.getClass().getSimpleName(),
+ expectedColumnType);
+ }
+ return null;
}
-
- // Don't log when an Integer value is in a Double column type
- if (!(value.getClass().equals(Integer.class) && expectedColumnType
- .getJavaEquivalentClass()
- .equals(Double.class)) && logger.isWarnEnabled()) {
- logger
- .warn("Cell ({},{}) has the value '{}' of data type '{}', which doesn't match the detected "
- + "column's data type '{}'. This cell gets value NULL in the DataSet.", cell.getRowIndex(),
- cell.getColumnIndex(), value, value.getClass().getSimpleName(), expectedColumnType);
- }
- return null;
}
private static String getFormulaCellValue(Workbook workbook, Cell cell) {
diff --git a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java b/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
index 7fdfff9..ed37de0 100644
--- a/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
+++ b/excel/src/test/java/org/apache/metamodel/excel/ExcelDataContextTest.java
@@ -841,7 +841,11 @@ public class ExcelDataContextTest extends TestCase {
.from(table)
.select("MIXING_DOUBLE_AND_INT")
.execute();
- IntStream.range(0, 20).forEach(i -> assertTrue(testWrongDatatypeDataSet.next()));
+ IntStream.range(0, 19).forEach(i -> {
+ assertTrue(testWrongDatatypeDataSet.next());
+ assertNotNull(testWrongDatatypeDataSet.getRow().getValue(0));
+ });
+ assertTrue(testWrongDatatypeDataSet.next());
assertNull(testWrongDatatypeDataSet.getRow().getValue(0));
assertFalse(testWrongDatatypeDataSet.next());
}
@@ -919,7 +923,7 @@ public class ExcelDataContextTest extends TestCase {
final ExcelDataContext dataContext = new ExcelDataContext(copyOf("src/test/resources/different_datatypes.xls"),
new ExcelConfiguration(ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE, null, true, false, true, 19));
final Table table = dataContext.getDefaultSchema().getTable(0);
- dataContext.executeUpdate(new InsertInto(table).value("INTEGER", 123));
+ dataContext.executeUpdate(new InsertInto(table).value("INTEGER", Integer.valueOf(123)));
final DataSet dataSet = dataContext.query().from(table).selectAll().where("INTEGER").eq(123).execute();
assertTrue(dataSet.next());
}
@@ -936,7 +940,7 @@ public class ExcelDataContextTest extends TestCase {
final ExcelDataContext dataContext = new ExcelDataContext(copyOf("src/test/resources/different_datatypes.xls"),
new ExcelConfiguration(ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE, null, true, false, true, 19));
final Table table = dataContext.getDefaultSchema().getTable(0);
- dataContext.executeUpdate(new Update(table).value("INTEGER", 1).value("INTEGER", 123));
+ dataContext.executeUpdate(new Update(table).value("INTEGER", 1).value("INTEGER", Integer.valueOf(123)));
final DataSet dataSet = dataContext.query().from(table).selectAll().where("INTEGER").eq(123).execute();
assertTrue(dataSet.next());
}