use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class SpanTupleTest method testGetters.
@Test
public void testGetters() throws ParseException {
// create data tuple first
Attribute[] attributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < attributes.length - 1; count++) {
attributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
attributes[attributes.length - 1] = SchemaConstants.SPAN_LIST_ATTRIBUTE;
List<IField> fields = new ArrayList<IField>(Arrays.asList(new IField[] { new StringField("bruce"), new StringField("lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("bruce was born in new york city and was grown up in los angeles") }));
IField spanField = createSpanListField();
fields.add(spanField);
spanTuple = new Tuple(new Schema(attributes), fields.toArray(new IField[fields.size()]));
IField spanFieldRetrieved = spanTuple.getField(SchemaConstants.SPAN_LIST);
Assert.assertTrue(spanFieldRetrieved instanceof ListField);
Assert.assertSame(spanField, spanFieldRetrieved);
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class Utils method addAttributeToSchema.
/**
* Add an attribute to an existing schema (if the attribute doesn't exist).
*
* @param schema
* @param attribute
* @return new schema
*/
public static Schema addAttributeToSchema(Schema schema, Attribute attribute) {
if (schema.containsField(attribute.getAttributeName())) {
return schema;
}
List<Attribute> attributes = new ArrayList<>(schema.getAttributes());
attributes.add(attribute);
Schema newSchema = new Schema(attributes.toArray(new Attribute[attributes.size()]));
return newSchema;
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class JsonSerializationTest method testAttribute.
@Test
public void testAttribute() {
Attribute attribute = new Attribute("attrName", AttributeType.TEXT);
TestUtils.testJsonSerialization(attribute);
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class JsonSerializationTest method testTuple.
@Test
public void testTuple() {
Schema schema = new Schema(Arrays.asList(new Attribute("_id", AttributeType._ID_TYPE), new Attribute("text", AttributeType.TEXT)));
Tuple tuple = new Tuple(schema, Arrays.asList(IDField.newRandomID(), new TextField("tuple test text")));
TestUtils.testJsonSerialization(tuple);
}
use of edu.uci.ics.textdb.api.schema.Attribute in project textdb by TextDB.
the class SchemaTest method testAddingNewAttribute.
@Test(expected = UnsupportedOperationException.class)
public void testAddingNewAttribute() {
// Should fail due to immutability
List<Attribute> attributes = schema.getAttributes();
attributes.add(new Attribute("sampleField_3", AttributeType.STRING));
}
Aggregations