Search in sources :

Example 71 with Schema

use of edu.uci.ics.texera.api.schema.Schema in project textdb by TextDB.

the class RelationManagerTest method test10.

/*
     * Test inserting multiple tuples to a table, getting them by a query, then deleting them by a query
     */
@Test
public void test10() throws Exception {
    String tableName = "relation_manager_test_table";
    String tableDirectory = "./index/test_table";
    Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING), new Attribute("number", AttributeType.STRING));
    RelationManager relationManager = RelationManager.getInstance();
    relationManager.deleteTable(tableName);
    relationManager.createTable(tableName, Paths.get(tableDirectory), tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
    dataWriter.open();
    Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"), new StringField("1"));
    dataWriter.insertTuple(insertedTuple);
    Tuple insertedTuple2 = new Tuple(tableSchema, new StringField("test"), new StringField("2"));
    IDField idField2 = dataWriter.insertTuple(insertedTuple2);
    Tuple insertedTuple3 = new Tuple(tableSchema, new StringField("test"), new StringField("3"));
    dataWriter.insertTuple(insertedTuple3);
    dataWriter.close();
    // test should match all 3 tuples
    Query allTupleQuery = new TermQuery(new Term("content", "test"));
    DataReader allTupleReader = relationManager.getTableDataReader(tableName, allTupleQuery);
    int tupleCounter = 0;
    allTupleReader.open();
    while (allTupleReader.getNextTuple() != null) {
        tupleCounter++;
    }
    allTupleReader.close();
    Assert.assertEquals(3, tupleCounter);
    // tuple 2 should be deleted
    Query tuple2Query = new TermQuery(new Term("number", "2"));
    dataWriter.open();
    dataWriter.deleteTuple(tuple2Query);
    dataWriter.close();
    Tuple deletedTuple = relationManager.getTupleByID(tableName, idField2);
    Assert.assertNull(deletedTuple);
    relationManager.deleteTable(tableName);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) IDField(edu.uci.ics.texera.api.field.IDField) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) Term(org.apache.lucene.index.Term) StringField(edu.uci.ics.texera.api.field.StringField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 72 with Schema

use of edu.uci.ics.texera.api.schema.Schema in project textdb by TextDB.

the class RelationManagerTest method test9.

/*
     * Test inserting a tuple to a table, then update it, then delete it 
     */
@Test
public void test9() throws Exception {
    String tableName = "relation_manager_test_table";
    String tableDirectory = "./index/test_table";
    Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING));
    RelationManager relationManager = RelationManager.getInstance();
    relationManager.deleteTable(tableName);
    relationManager.createTable(tableName, Paths.get(tableDirectory), tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
    dataWriter.open();
    Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"));
    IDField idField = dataWriter.insertTuple(insertedTuple);
    dataWriter.close();
    Tuple returnedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertEquals(insertedTuple.getField("content").getValue().toString(), returnedTuple.getField("content").getValue().toString());
    dataWriter.open();
    Tuple updatedTuple = new Tuple(tableSchema, new StringField("testUpdate"));
    dataWriter.updateTuple(updatedTuple, idField);
    dataWriter.close();
    Tuple returnedUpdatedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertEquals(updatedTuple.getField("content").getValue().toString(), returnedUpdatedTuple.getField("content").getValue().toString());
    dataWriter.open();
    dataWriter.deleteTupleByID(idField);
    dataWriter.close();
    Tuple deletedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertNull(deletedTuple);
    relationManager.deleteTable(tableName);
}
Also used : IDField(edu.uci.ics.texera.api.field.IDField) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) StringField(edu.uci.ics.texera.api.field.StringField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 73 with Schema

use of edu.uci.ics.texera.api.schema.Schema in project textdb by TextDB.

the class RelationManagerTest method test8.

/*
     * Test inserting a tuple to a table and then delete it 
     */
@Test
public void test8() throws Exception {
    String tableName = "relation_manager_test_table";
    String tableDirectory = "./index/test_table";
    Schema tableSchema = new Schema(new Attribute("content", AttributeType.STRING));
    RelationManager relationManager = RelationManager.getInstance();
    relationManager.deleteTable(tableName);
    relationManager.createTable(tableName, Paths.get(tableDirectory), tableSchema, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(tableName);
    dataWriter.open();
    Tuple insertedTuple = new Tuple(tableSchema, new StringField("test"));
    IDField idField = dataWriter.insertTuple(insertedTuple);
    dataWriter.close();
    Tuple returnedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertEquals(insertedTuple.getField("content").getValue().toString(), returnedTuple.getField("content").getValue().toString());
    dataWriter.open();
    dataWriter.deleteTupleByID(idField);
    dataWriter.close();
    Tuple deletedTuple = relationManager.getTupleByID(tableName, idField);
    Assert.assertNull(deletedTuple);
    relationManager.deleteTable(tableName);
}
Also used : IDField(edu.uci.ics.texera.api.field.IDField) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) StringField(edu.uci.ics.texera.api.field.StringField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 74 with Schema

use of edu.uci.ics.texera.api.schema.Schema in project textdb by TextDB.

the class RelationManagerTest method test2.

/*
     * Test the information about "schema catalog" itself is stored properly.
     */
@Test
public void test2() throws Exception {
    String schemaCatalogDirectory = relationManager.getTableDirectory(CatalogConstants.SCHEMA_CATALOG);
    Analyzer schemaCatalogLuceneAnalyzer = relationManager.getTableAnalyzer(CatalogConstants.SCHEMA_CATALOG);
    Schema schemaCatalogSchema = relationManager.getTableSchema(CatalogConstants.SCHEMA_CATALOG);
    Assert.assertEquals(schemaCatalogDirectory, CatalogConstants.SCHEMA_CATALOG_DIRECTORY.toRealPath().toString());
    Assert.assertTrue(schemaCatalogLuceneAnalyzer instanceof StandardAnalyzer);
    Assert.assertEquals(schemaCatalogSchema, Schema.Builder.getSchemaWithID(CatalogConstants.SCHEMA_CATALOG_SCHEMA));
}
Also used : Schema(edu.uci.ics.texera.api.schema.Schema) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Test(org.junit.Test)

Example 75 with Schema

use of edu.uci.ics.texera.api.schema.Schema in project textdb by TextDB.

the class DictionaryMatcherTest method testMultipleWordsQueryUsingPhrase.

/**
 * Scenario S-10:verifies ITuple returned by DictionaryMatcher and multiple
 * word queries using PHRASE OPERATOR
 */
@Test
public void testMultipleWordsQueryUsingPhrase() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("george lin lin"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list = new ArrayList<Span>();
    Span span = new Span("firstName", 0, 14, "george lin lin", "george lin lin");
    list.add(span);
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = RESULTS_ATTRIBUTE;
    IField[] fields1 = { new StringField("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is Angry"), new ListField<Span>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    List<Tuple> expectedResults = new ArrayList<Tuple>();
    expectedResults.add(tuple1);
    List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
    List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.PHRASE_INDEXBASED);
    boolean contains = TestUtils.equals(expectedResults, returnedResults);
    Assert.assertTrue(contains);
}
Also used : Dictionary(edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary) Attribute(edu.uci.ics.texera.api.schema.Attribute) 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) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

Schema (edu.uci.ics.texera.api.schema.Schema)134 Test (org.junit.Test)109 Tuple (edu.uci.ics.texera.api.tuple.Tuple)106 ArrayList (java.util.ArrayList)97 IField (edu.uci.ics.texera.api.field.IField)96 Span (edu.uci.ics.texera.api.span.Span)86 TextField (edu.uci.ics.texera.api.field.TextField)77 Attribute (edu.uci.ics.texera.api.schema.Attribute)76 StringField (edu.uci.ics.texera.api.field.StringField)72 IntegerField (edu.uci.ics.texera.api.field.IntegerField)71 DoubleField (edu.uci.ics.texera.api.field.DoubleField)60 DateField (edu.uci.ics.texera.api.field.DateField)57 SimpleDateFormat (java.text.SimpleDateFormat)54 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)29 ListField (edu.uci.ics.texera.api.field.ListField)21 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)15 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)14 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)13 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)9 JoinDistancePredicate (edu.uci.ics.texera.dataflow.join.JoinDistancePredicate)9