incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/2] git commit: BLUR-280: Support for null family.
Date Sat, 26 Oct 2013 14:57:27 GMT
Updated Branches:
  refs/heads/master 294294b4a -> e75fab65f


BLUR-280: Support for null family.

Signed-off-by: Aaron McCurry <amccurry@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2e04778d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2e04778d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2e04778d

Branch: refs/heads/master
Commit: 2e04778d68ff6344ad8093bee9273e7441c909ff
Parents: 294294b
Author: Gagan <gagandeepjuneja@gmail.com>
Authored: Tue Oct 22 19:39:51 2013 +0530
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sat Oct 26 10:56:36 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/analysis/BaseFieldManager.java  | 27 +++++++++--
 .../org/apache/blur/analysis/FieldManager.java  |  2 +
 .../blur/analysis/BaseFieldManagerTest.java     | 51 +++++++++++++++++++-
 .../org/apache/blur/utils/BlurConstants.java    |  1 +
 4 files changed, 77 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2e04778d/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java b/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
index 36e4202..0121d72 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java
@@ -208,6 +208,9 @@ public abstract class BaseFieldManager extends FieldManager {
   public List<Field> getFields(String rowId, Record record) throws IOException {
     List<Field> fields = new ArrayList<Field>();
     String family = record.getFamily();
+    if(family == null || family.isEmpty()){
+    	family = BlurConstants.DEFAULT_FAMILY;
+    }
     List<Column> columns = record.getColumns();
     addDefaultFields(fields, rowId, record);
     for (Column column : columns) {
@@ -250,10 +253,13 @@ public abstract class BaseFieldManager extends FieldManager {
     String recordId = record.getRecordId();
 
     validateNotNull(rowId, BlurConstants.ROW_ID);
-    validateNotNull(family, BlurConstants.FAMILY);
     validateNotNull(recordId, BlurConstants.RECORD_ID);
-
-    fields.add(new Field(BlurConstants.FAMILY, family, ID_TYPE));
+    
+    if (family == null){
+    	fields.add(new Field(BlurConstants.FAMILY, BlurConstants.DEFAULT_FAMILY, ID_TYPE));
+    }else{
+    	fields.add(new Field(BlurConstants.FAMILY, family, ID_TYPE));
+    }
     fields.add(new Field(BlurConstants.ROW_ID, rowId, ID_TYPE));
     fields.add(new Field(BlurConstants.RECORD_ID, recordId, ID_TYPE));
   }
@@ -305,6 +311,9 @@ public abstract class BaseFieldManager extends FieldManager {
   @Override
   public boolean addColumnDefinition(String family, String columnName, String subColumnName,
boolean fieldLessIndexed,
       String fieldType, Map<String, String> props) throws IOException {
+	if(family == null){
+		family = BlurConstants.DEFAULT_FAMILY;
+	}
     String baseFieldName = family + "." + columnName;
     String fieldName;
     if (subColumnName != null) {
@@ -632,5 +641,17 @@ public abstract class BaseFieldManager extends FieldManager {
   public boolean isStrict() {
     return _strict;
   }
+  
+  @Override
+  public String resolveField(String field){
+	  if (_fieldNameToDefMap.get(field) != null || isBuiltInField(field) || field.equals(_fieldLessField)){
+		  return field;
+	  }
 
+	  String newField = BlurConstants.DEFAULT_FAMILY + "." + field;
+	  if (_fieldNameToDefMap.get(newField) != null){
+		  return newField;
+	  }
+	  return field;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2e04778d/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java b/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
index 52b4062..050e6cc 100644
--- a/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
+++ b/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java
@@ -268,5 +268,7 @@ public abstract class FieldManager {
   public abstract void registerType(Class<? extends FieldTypeDefinition> c);
   
   public abstract Set<String> getFieldNames() throws IOException;
+  
+  public abstract String resolveField(String field);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2e04778d/blur-query/src/test/java/org/apache/blur/analysis/BaseFieldManagerTest.java
----------------------------------------------------------------------
diff --git a/blur-query/src/test/java/org/apache/blur/analysis/BaseFieldManagerTest.java b/blur-query/src/test/java/org/apache/blur/analysis/BaseFieldManagerTest.java
index 6038698..b7158db 100644
--- a/blur-query/src/test/java/org/apache/blur/analysis/BaseFieldManagerTest.java
+++ b/blur-query/src/test/java/org/apache/blur/analysis/BaseFieldManagerTest.java
@@ -54,6 +54,24 @@ public class BaseFieldManagerTest {
       assertFieldEquals(fields.get(c++), field);
     }
   }
+  
+  @Test
+  public void testFieldManagerWithNullFamily() throws IOException {
+    BaseFieldManager memoryFieldManager = newFieldManager(true);
+    memoryFieldManager.addColumnDefinition(null, "col1", null, true, "text", null);
+
+    Record record = new Record();
+    record.setRecordId("1213");
+    record.addToColumns(new Column("col1", "value1"));
+
+    List<Field> fields = getFields(null, "1", "1213", newTextField(memoryFieldManager.resolveField("col1"),
"value1"),
+        newTextFieldNoStore(_fieldLessField, "value1"));
+
+    int c = 0;
+    for (Field field : memoryFieldManager.getFields("1", record)) {
+      assertFieldEquals(fields.get(c++), field);
+    }
+  }
 
   @Test
   public void testFieldManagerMultipleColumnsSameName() throws IOException {
@@ -125,6 +143,33 @@ public class BaseFieldManagerTest {
       assertFieldEquals(fields2.get(c2++), field);
     }
   }
+  
+  @Test
+  public void testFieldManagerMultipleColumnsDifferentNamesNullFamilies() throws IOException
{
+    BaseFieldManager memoryFieldManager = newFieldManager(true);
+    memoryFieldManager.addColumnDefinition(null, "col1", null, false, "text", null);
+    memoryFieldManager.addColumnDefinition(null, "col2", null, false, "text", null);
+
+    Record record1 = new Record();
+    record1.setRecordId("1213");
+    record1.addToColumns(new Column("col1", "value1"));
+
+    List<Field> fields1 = getFields(null, "1", "1213", newTextField(memoryFieldManager.resolveField("col1"),
"value1"));
+    int c1 = 0;	
+    for (Field field : memoryFieldManager.getFields("1", record1)) {
+      assertFieldEquals(fields1.get(c1++), field);
+    }
+
+    Record record2 = new Record();
+    record2.setRecordId("1213");
+    record2.addToColumns(new Column("col2", "value1"));
+
+    List<Field> fields2 = getFields(null, "1", "1213", newTextField(memoryFieldManager.resolveField("col2"),
"value1"));
+    int c2 = 0;
+    for (Field field : memoryFieldManager.getFields("1", record2)) {
+      assertFieldEquals(fields2.get(c2++), field);
+    }
+  }
 
   @Test
   public void testFieldManagerSubNameWithMainColumnNameNoParent() throws IOException {
@@ -149,7 +194,11 @@ public class BaseFieldManagerTest {
 
   private List<Field> getFields(String family, String rowId, String recordId, Field...
fields) {
     List<Field> fieldLst = new ArrayList<Field>();
-    fieldLst.add(new Field(BlurConstants.FAMILY, family, BaseFieldManager.ID_TYPE));
+    if(family != null){
+    	fieldLst.add(new Field(BlurConstants.FAMILY, family, BaseFieldManager.ID_TYPE));
+    }else{
+    	fieldLst.add(new Field(BlurConstants.FAMILY, BlurConstants.DEFAULT_FAMILY, BaseFieldManager.ID_TYPE));
+    }
     fieldLst.add(new Field(BlurConstants.ROW_ID, rowId, BaseFieldManager.ID_TYPE));
     fieldLst.add(new Field(BlurConstants.RECORD_ID, recordId, BaseFieldManager.ID_TYPE));
     for (Field field : fields) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2e04778d/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
----------------------------------------------------------------------
diff --git a/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java b/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
index 07b5d7a..ccf3ea9 100644
--- a/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
+++ b/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
@@ -32,6 +32,7 @@ public class BlurConstants {
   public static final String ROW_ID = "rowid";
   public static final String RECORD_ID = "recordid";
   public static final String FAMILY = "family";
+  public static final String DEFAULT_FAMILY = "_default_";
   public static final String SUPER = "super";
   public static final String SEP = ".";
 


Mime
View raw message