Search in sources :

Example 26 with DateField

use of edu.uci.ics.texera.api.field.DateField in project textdb by TextDB.

the class ExcelSinkTest method attributeTypeTest.

@Test
public // writing 10000 tuples
void attributeTypeTest() 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 inputOperator = Mockito.mock(IOperator.class);
    Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
    OngoingStubbing<Tuple> stubbing = Mockito.when(inputOperator.getNextTuple());
    for (Tuple t : tupleList) {
        stubbing = stubbing.thenReturn(t);
    }
    stubbing = stubbing.thenReturn(null);
    // excel writing test
    excelSink = new ExcelSink(new ExcelSinkPredicate());
    excelSink.setInputOperator(inputOperator);
    excelSink.open();
    excelSink.collectAllTuples();
    excelSink.close();
    Files.deleteIfExists(excelSink.getFilePath());
}
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) Test(org.junit.Test)

Example 27 with DateField

use of edu.uci.ics.texera.api.field.DateField in project textdb by TextDB.

the class MysqlSinkTest method test2TupleInsertion.

/**
 * Create two tuples, insert into mysql
 * @throws ParseException
 */
public void test2TupleInsertion() throws Exception {
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare the expected result list
    List<Span> list = new ArrayList<>();
    Span span1 = new Span("firstName", 0, 5, "bruce", "bruce");
    Span span2 = new Span("lastnName", 0, 5, "jacki", "jacki");
    list.add(span1);
    list.add(span2);
    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] = SchemaConstants.SPAN_LIST_ATTRIBUTE;
    IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<>(list) };
    IField[] fields2 = { new StringField("test"), new StringField("jackie chan"), new IntegerField(0), new DoubleField(6.0), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("09-18-1994")), new TextField("Angry Bird"), new ListField<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
    IOperator localInputOperator = Mockito.mock(IOperator.class);
    Mockito.when(localInputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes)).thenReturn(null);
    Mockito.when(localInputOperator.getNextTuple()).thenReturn(tuple1).thenReturn(tuple2).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) 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)

Example 28 with DateField

use of edu.uci.ics.texera.api.field.DateField 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)

Example 29 with DateField

use of edu.uci.ics.texera.api.field.DateField in project textdb by TextDB.

the class DictionaryMatcherTest method testMultipleWordQueryInTextFieldUsingScan2.

@Test
public void testMultipleWordQueryInTextFieldUsingScan2() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("tall fair"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list1 = new ArrayList<Span>();
    Span span1 = new Span("description", 0, 9, "tall fair", "Tall Fair");
    list1.add(span1);
    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[] fields2 = { new StringField("christian john wayne"), new StringField("rock bale"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Tall Fair"), new ListField<Span>(list1) };
    Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
    List<Tuple> expectedResults = new ArrayList<Tuple>();
    expectedResults.add(tuple2);
    List<String> attributeNames = Arrays.asList(TestConstants.FIRST_NAME, TestConstants.LAST_NAME, TestConstants.DESCRIPTION);
    List<Tuple> returnedResults = DictionaryMatcherTestHelper.getQueryResults(PEOPLE_TABLE, dictionary, attributeNames, KeywordMatchingType.SUBSTRING_SCANBASED);
    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)

Example 30 with DateField

use of edu.uci.ics.texera.api.field.DateField in project textdb by TextDB.

the class DictionaryMatcherTest method testSingleWordQueryInStringFieldUsingScan.

/**
 * Scenario: verifies GetNextTuple of DictionaryMatcher and single word
 * queries in String Field using SCANOPERATOR
 */
@Test
public void testSingleWordQueryInStringFieldUsingScan() throws Exception {
    ArrayList<String> names = new ArrayList<String>(Arrays.asList("bruce"));
    Dictionary dictionary = new Dictionary(names);
    // create a data tuple first
    List<Span> list = new ArrayList<Span>();
    Span span = new Span("firstName", 0, 5, "bruce", "bruce");
    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("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall 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.SUBSTRING_SCANBASED);
    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

DateField (edu.uci.ics.texera.api.field.DateField)59 DoubleField (edu.uci.ics.texera.api.field.DoubleField)58 IField (edu.uci.ics.texera.api.field.IField)58 IntegerField (edu.uci.ics.texera.api.field.IntegerField)58 StringField (edu.uci.ics.texera.api.field.StringField)58 TextField (edu.uci.ics.texera.api.field.TextField)58 SimpleDateFormat (java.text.SimpleDateFormat)56 Schema (edu.uci.ics.texera.api.schema.Schema)55 Tuple (edu.uci.ics.texera.api.tuple.Tuple)55 ArrayList (java.util.ArrayList)55 Test (org.junit.Test)53 Span (edu.uci.ics.texera.api.span.Span)52 Attribute (edu.uci.ics.texera.api.schema.Attribute)48 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)29 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)4 ParseException (java.text.ParseException)3 Random (java.util.Random)2 ListField (edu.uci.ics.texera.api.field.ListField)1 Date (java.util.Date)1