Commit 6c00ad96 by Harish Butani

add primitive attribute stores

parent 0a208d18
...@@ -18,8 +18,14 @@ ...@@ -18,8 +18,14 @@
package org.apache.hadoop.metadata; package org.apache.hadoop.metadata;
import org.apache.hadoop.metadata.types.AttributeInfo;
import org.apache.hadoop.metadata.types.DataTypes;
import org.apache.hadoop.metadata.types.FieldMapping; import org.apache.hadoop.metadata.types.FieldMapping;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
/** /**
* An instance whose structure is associated with a IDataType. * An instance whose structure is associated with a IDataType.
* This is obtained by a call to 'createInstance' or the result of a Query. * This is obtained by a call to 'createInstance' or the result of a Query.
...@@ -31,4 +37,30 @@ import org.apache.hadoop.metadata.types.FieldMapping; ...@@ -31,4 +37,30 @@ import org.apache.hadoop.metadata.types.FieldMapping;
public interface ITypedInstance extends IInstance { public interface ITypedInstance extends IInstance {
FieldMapping fieldMapping(); FieldMapping fieldMapping();
public void setNull(String attrName) throws MetadataException;
public boolean getBoolean(String attrName) throws MetadataException;
public byte getByte(String attrName) throws MetadataException;
public short getShort(String attrName) throws MetadataException;
public int getInt(String attrName) throws MetadataException;
public long getLong(String attrName) throws MetadataException;
public float getFloat(String attrName) throws MetadataException;
public double getDouble(String attrName) throws MetadataException;
public BigInteger getBigInt(String attrName) throws MetadataException;
public BigDecimal getBigDecimal(String attrName) throws MetadataException ;
public Date getDate(String attrName) throws MetadataException;
public String getString(String attrName) throws MetadataException;
public void setBoolean(String attrName, boolean val) throws MetadataException;
public void setByte(String attrName, byte val) throws MetadataException;
public void setShort(String attrName, short val) throws MetadataException;
public void setInt(String attrName, int val) throws MetadataException;
public void setLong(String attrName, long val) throws MetadataException;
public void setFloat(String attrName, float val) throws MetadataException;
public void setDouble(String attrName, double val) throws MetadataException;
public void setBigInt(String attrName, BigInteger val) throws MetadataException;
public void setBigDecimal(String attrName, BigDecimal val) throws MetadataException;
public void setDate(String attrName, Date val) throws MetadataException;
public void setString(String attrName, String val) throws MetadataException;
} }
...@@ -25,6 +25,10 @@ import org.apache.hadoop.metadata.ITypedReferenceableInstance; ...@@ -25,6 +25,10 @@ import org.apache.hadoop.metadata.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.types.FieldMapping; import org.apache.hadoop.metadata.types.FieldMapping;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
public class Id implements ITypedReferenceableInstance { public class Id implements ITypedReferenceableInstance {
public final long id; public final long id;
...@@ -38,7 +42,7 @@ public class Id implements ITypedReferenceableInstance { ...@@ -38,7 +42,7 @@ public class Id implements ITypedReferenceableInstance {
} }
public Id(String className) { public Id(String className) {
this(- System.currentTimeMillis(), 0, className); this(-System.currentTimeMillis(), 0, className);
} }
public boolean isUnassigned() { public boolean isUnassigned() {
...@@ -83,4 +87,96 @@ public class Id implements ITypedReferenceableInstance { ...@@ -83,4 +87,96 @@ public class Id implements ITypedReferenceableInstance {
public FieldMapping fieldMapping() { public FieldMapping fieldMapping() {
return null; return null;
} }
public void setNull(String attrName) throws MetadataException {
set(attrName, null);
}
public boolean getBoolean(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public byte getByte(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public short getShort(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public int getInt(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public long getLong(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public float getFloat(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public double getDouble(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public BigInteger getBigInt(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public BigDecimal getBigDecimal(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public Date getDate(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public String getString(String attrName) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setBoolean(String attrName, boolean val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setByte(String attrName, byte val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setShort(String attrName, short val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setInt(String attrName, int val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setLong(String attrName, long val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setFloat(String attrName, float val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setDouble(String attrName, double val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setBigInt(String attrName, BigInteger val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setBigDecimal(String attrName, BigDecimal val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setDate(String attrName, Date val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
public void setString(String attrName, String val) throws MetadataException {
throw new MetadataException("Get/Set not supported on an Id object");
}
} }
...@@ -37,7 +37,7 @@ import java.util.List; ...@@ -37,7 +37,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class StructStore extends AttributeStores.AbstractAttributeStore implements IAttributeStore { public abstract class StructStore extends AttributeStores.AbstractAttributeStore implements IAttributeStore {
final StructType structType; final StructType structType;
final ImmutableMap<AttributeInfo, IAttributeStore> attrStores; final ImmutableMap<AttributeInfo, IAttributeStore> attrStores;
......
...@@ -49,12 +49,14 @@ public class DataTypes { ...@@ -49,12 +49,14 @@ public class DataTypes {
CLASS; CLASS;
}; };
static abstract class PrimitiveType<T> extends AbstractDataType<T> { public static abstract class PrimitiveType<T> extends AbstractDataType<T> {
@Override @Override
public TypeCategory getTypeCategory() { public TypeCategory getTypeCategory() {
return TypeCategory.PRIMITIVE; return TypeCategory.PRIMITIVE;
} }
public abstract T nullValue();
} }
public static BooleanType BOOLEAN_TYPE = new BooleanType(); public static BooleanType BOOLEAN_TYPE = new BooleanType();
...@@ -84,6 +86,10 @@ public class DataTypes { ...@@ -84,6 +86,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Boolean nullValue() {
return Boolean.FALSE;
}
} }
public static ByteType BYTE_TYPE = new ByteType(); public static ByteType BYTE_TYPE = new ByteType();
...@@ -113,6 +119,10 @@ public class DataTypes { ...@@ -113,6 +119,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Byte nullValue() {
return 0;
}
} }
public static ShortType SHORT_TYPE = new ShortType(); public static ShortType SHORT_TYPE = new ShortType();
...@@ -142,6 +152,10 @@ public class DataTypes { ...@@ -142,6 +152,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Short nullValue() {
return 0;
}
} }
public static IntType INT_TYPE = new IntType(); public static IntType INT_TYPE = new IntType();
...@@ -171,6 +185,10 @@ public class DataTypes { ...@@ -171,6 +185,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Integer nullValue() {
return 0;
}
} }
public static LongType LONG_TYPE = new LongType(); public static LongType LONG_TYPE = new LongType();
...@@ -200,6 +218,10 @@ public class DataTypes { ...@@ -200,6 +218,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Long nullValue() {
return 0l;
}
} }
public static FloatType FLOAT_TYPE = new FloatType(); public static FloatType FLOAT_TYPE = new FloatType();
...@@ -229,6 +251,10 @@ public class DataTypes { ...@@ -229,6 +251,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Float nullValue() {
return 0.0f;
}
} }
public static DoubleType DOUBLE_TYPE = new DoubleType(); public static DoubleType DOUBLE_TYPE = new DoubleType();
...@@ -258,6 +284,10 @@ public class DataTypes { ...@@ -258,6 +284,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Double nullValue() {
return 0.0;
}
} }
public static BigIntegerType BIGINTEGER_TYPE = new BigIntegerType(); public static BigIntegerType BIGINTEGER_TYPE = new BigIntegerType();
...@@ -293,6 +323,10 @@ public class DataTypes { ...@@ -293,6 +323,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public BigInteger nullValue() {
return null;
}
} }
public static BigDecimalType BIGDECIMAL_TYPE = new BigDecimalType(); public static BigDecimalType BIGDECIMAL_TYPE = new BigDecimalType();
...@@ -328,6 +362,10 @@ public class DataTypes { ...@@ -328,6 +362,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public BigDecimal nullValue() {
return null;
}
} }
public static DateType DATE_TYPE = new DateType(); public static DateType DATE_TYPE = new DateType();
...@@ -361,6 +399,10 @@ public class DataTypes { ...@@ -361,6 +399,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public Date nullValue() {
return null;
}
} }
public static StringType STRING_TYPE = new StringType(); public static StringType STRING_TYPE = new StringType();
...@@ -382,6 +424,10 @@ public class DataTypes { ...@@ -382,6 +424,10 @@ public class DataTypes {
} }
return convertNull(m); return convertNull(m);
} }
public String nullValue() {
return null;
}
} }
static String ARRAY_TYPE_PREFIX = "array<"; static String ARRAY_TYPE_PREFIX = "array<";
...@@ -423,7 +469,7 @@ public class DataTypes { ...@@ -423,7 +469,7 @@ public class DataTypes {
it = (Iterator)val; it = (Iterator)val;
} }
if ( it != null ) { if ( it != null ) {
ImmutableCollection.Builder<?> b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder(); ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder();
while (it.hasNext() ) { while (it.hasNext() ) {
b.add(elemType.convert(it.next(), b.add(elemType.convert(it.next(),
r.allowNullsInCollections() ? Multiplicity.OPTIONAL : Multiplicity.REQUIRED)); r.allowNullsInCollections() ? Multiplicity.OPTIONAL : Multiplicity.REQUIRED));
...@@ -451,7 +497,7 @@ public class DataTypes { ...@@ -451,7 +497,7 @@ public class DataTypes {
if ( val == null || elemType.getTypeCategory() != TypeCategory.CLASS ) { if ( val == null || elemType.getTypeCategory() != TypeCategory.CLASS ) {
return val; return val;
} }
ImmutableCollection.Builder<?> b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder(); ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder();
Iterator it = val.iterator(); Iterator it = val.iterator();
while(it.hasNext()) { while(it.hasNext()) {
Object elem = it.next(); Object elem = it.next();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment