Search in sources :

Example 81 with Attribute

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();
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Random(java.util.Random) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DoubleField(edu.uci.ics.texera.api.field.DoubleField)

Example 82 with Attribute

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();
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) Test(org.junit.Test)

Example 83 with Attribute

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;
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) StringField(edu.uci.ics.texera.api.field.StringField) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 84 with Attribute

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;
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) IField(edu.uci.ics.texera.api.field.IField) Document(org.apache.lucene.document.Document)

Example 85 with Attribute

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);
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) File(java.io.File) Test(org.junit.Test)

Aggregations

Attribute (edu.uci.ics.texera.api.schema.Attribute)98 Test (org.junit.Test)81 Tuple (edu.uci.ics.texera.api.tuple.Tuple)78 ArrayList (java.util.ArrayList)76 Schema (edu.uci.ics.texera.api.schema.Schema)75 IField (edu.uci.ics.texera.api.field.IField)60 StringField (edu.uci.ics.texera.api.field.StringField)56 TextField (edu.uci.ics.texera.api.field.TextField)56 IntegerField (edu.uci.ics.texera.api.field.IntegerField)54 DoubleField (edu.uci.ics.texera.api.field.DoubleField)53 Span (edu.uci.ics.texera.api.span.Span)51 DateField (edu.uci.ics.texera.api.field.DateField)50 SimpleDateFormat (java.text.SimpleDateFormat)47 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)28 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)9 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)8 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)6 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)5