use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class MysqlSinkTest method testTupleListInsertion.
/**
* Create 10000 tuples with all regular fields
* Insert into mysql database
*/
public void testTupleListInsertion() throws Exception {
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.FIRST_NAME);
attributeNames.add(TestConstants.LAST_NAME);
attributeNames.add(TestConstants.AGE);
attributeNames.add(TestConstants.HEIGHT);
attributeNames.add(TestConstants.DATE_OF_BIRTH);
attributeNames.add(TestConstants.DESCRIPTION);
// Prepare Schema
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length];
for (int count = 0; count < schemaAttributes.length; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
// Prepare 10000 tuples as a tupleList
int testSize = 10000;
Random rand = new Random();
List<Tuple> tupleList = new ArrayList<Tuple>();
for (int i = 0; i < testSize; i++) {
IField[] fields = { new StringField(getRandomString()), new StringField(getRandomString()), new IntegerField(rand.nextInt()), new DoubleField(rand.nextDouble() * rand.nextInt()), new DateField(getRandomDate()), new TextField(getRandomString()) };
tupleList.add(new Tuple(new Schema(schemaAttributes), fields));
}
assert (tupleList.size() == testSize);
IOperator localInputOperator = Mockito.mock(IOperator.class);
Mockito.when(localInputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
OngoingStubbing<Tuple> stubbing = Mockito.when(localInputOperator.getNextTuple());
for (Tuple t : tupleList) {
stubbing = stubbing.thenReturn(t);
}
stubbing = stubbing.thenReturn(null);
mysqlSink.setInputOperator(localInputOperator);
mysqlSink.open();
mysqlSink.processTuples();
mysqlSink.close();
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class TupleSinkTest method testOpenClose.
@Test
public void testOpenClose() throws Exception {
TupleSink tupleSink = new TupleSink();
tupleSink.setInputOperator(inputOperator);
tupleSink.open();
// verify that inputOperator called open() method
// assert that the tuple stream sink removes the PAYLOAD attribute
Assert.assertEquals(new Schema(SchemaConstants._ID_ATTRIBUTE, new Attribute("content", AttributeType.TEXT)), tupleSink.getOutputSchema());
tupleSink.close();
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class CatalogConstants method getSchemaCatalogTuples.
/**
* Gets the tuples to be inserted to the schema catalog.
*
* @param tableName
* @param tableDirectory
* @param luceneAnalyzerStr
* @return
* @throws StorageException
*/
public static List<Tuple> getSchemaCatalogTuples(String tableName, Schema tableSchema) {
List<Tuple> schemaCatalogTuples = new ArrayList<>();
for (int i = 0; i < tableSchema.getAttributes().size(); i++) {
Attribute attr = tableSchema.getAttributes().get(i);
Tuple schemaTuple = new Tuple(SCHEMA_CATALOG_SCHEMA, new StringField(tableName), new StringField(attr.getName()), new StringField(attr.getType().toString().toLowerCase()), new IntegerField(i));
schemaCatalogTuples.add(schemaTuple);
}
return schemaCatalogTuples;
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class DataWriter method getLuceneDocument.
/*
* Converts a Texera tuple to a Lucene document
*/
private static Document getLuceneDocument(Tuple tuple) {
List<IField> fields = tuple.getFields();
List<Attribute> attributes = tuple.getSchema().getAttributes();
Document doc = new Document();
for (int count = 0; count < fields.size(); count++) {
IField field = fields.get(count);
Attribute attr = attributes.get(count);
AttributeType attributeType = attr.getType();
doc.add(StorageUtils.getLuceneField(attributeType, attr.getName(), field.getValue()));
}
return doc;
}
use of edu.uci.ics.texera.api.schema.Attribute in project textdb by TextDB.
the class RelationManagerTest method test3.
/*
* Create a table and test if table's information can be retrieved successfully.
*/
@Test
public void test3() throws Exception {
String tableName = "relation_manager_test_table_1";
String tableDirectory = "./index/test_table_1/";
Schema tableSchema = new Schema(new Attribute("city", AttributeType.STRING), new Attribute("description", AttributeType.TEXT), new Attribute("tax rate", AttributeType.DOUBLE), new Attribute("population", AttributeType.INTEGER), new Attribute("record time", AttributeType.DATE));
String tableLuceneAnalyzerString = LuceneAnalyzerConstants.standardAnalyzerString();
Analyzer tableLuceneAnalyzer = LuceneAnalyzerConstants.getLuceneAnalyzer(tableLuceneAnalyzerString);
RelationManager relationManager = RelationManager.getInstance();
relationManager.deleteTable(tableName);
relationManager.createTable(tableName, Paths.get(tableDirectory), tableSchema, tableLuceneAnalyzerString);
Assert.assertEquals(new File(tableDirectory).getCanonicalPath(), relationManager.getTableDirectory(tableName));
Assert.assertEquals(Schema.Builder.getSchemaWithID(tableSchema), relationManager.getTableSchema(tableName));
Assert.assertEquals(tableLuceneAnalyzer.getClass(), relationManager.getTableAnalyzer(tableName).getClass());
relationManager.deleteTable(tableName);
}
Aggregations