You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samoa.apache.org by gd...@apache.org on 2016/04/19 10:35:02 UTC
[03/19] incubator-samoa git commit: SAMOA-58: Needed to loop over all
Union types to determine if Union-typed field is numeric or not.
SAMOA-58: Needed to loop over all Union types to determine if Union-typed field is numeric or not.
Project: http://git-wip-us.apache.org/repos/asf/incubator-samoa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-samoa/commit/78ae8fce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-samoa/tree/78ae8fce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-samoa/diff/78ae8fce
Branch: refs/heads/master
Commit: 78ae8fce13927afd4ec04d1f83e7a500009520e2
Parents: 5d131e2
Author: edi_bice <ed...@yahoo.com>
Authored: Tue Feb 23 10:49:47 2016 -0500
Committer: Gianmarco De Francisci Morales <gd...@apache.org>
Committed: Tue Apr 19 11:33:42 2016 +0300
----------------------------------------------------------------------
.../org/apache/samoa/instances/AvroLoader.java | 23 ++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/78ae8fce/samoa-instances/src/main/java/org/apache/samoa/instances/AvroLoader.java
----------------------------------------------------------------------
diff --git a/samoa-instances/src/main/java/org/apache/samoa/instances/AvroLoader.java b/samoa-instances/src/main/java/org/apache/samoa/instances/AvroLoader.java
index e7f18b5..9f0664c 100644
--- a/samoa-instances/src/main/java/org/apache/samoa/instances/AvroLoader.java
+++ b/samoa-instances/src/main/java/org/apache/samoa/instances/AvroLoader.java
@@ -254,15 +254,30 @@ public abstract class AvroLoader implements Loader {
List<String> attributeLabels = attributeSchema.getEnumSymbols();
attributes.add(new Attribute(field.name(), attributeLabels));
}
- else if (attributeSchema.getType() == Schema.Type.DOUBLE
- || attributeSchema.getType() == Schema.Type.FLOAT
- || attributeSchema.getType() == Schema.Type.LONG
- || attributeSchema.getType() == Schema.Type.INT)
+ else if (isNumeric(field))
attributes.add(new Attribute(field.name()));
}
return new InstanceInformation(relation, attributes);
}
+ private boolean isNumeric(Field field) {
+ if (field.schema().getType() == Schema.Type.DOUBLE
+ || field.schema().getType() == Schema.Type.FLOAT
+ || field.schema().getType() == Schema.Type.LONG
+ || field.schema().getType() == Schema.Type.INT)
+ return true;
+ if (field.schema().getType() == Schema.Type.UNION) {
+ for (Schema schema: field.schema().getTypes()) {
+ if (schema.getType() == Schema.Type.DOUBLE
+ || schema.getType() == Schema.Type.FLOAT
+ || schema.getType() == Schema.Type.LONG
+ || schema.getType() == Schema.Type.INT)
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Identifies if the dataset is is Sparse or Dense
*