Search in sources :

Example 46 with StringField

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

the class AggregatorTest method testMaxDOBMinNameAggregation.

// TEST 9: Find max in DOB and min in Name (String) column
@Test
public void testMaxDOBMinNameAggregation() throws Exception {
    Attribute attribute1 = TestConstants.DATE_OF_BIRTH_ATTR;
    String attributeName1 = attribute1.getName();
    AggregationType aggType1 = AggregationType.MAX;
    Attribute attribute2 = TestConstants.FIRST_NAME_ATTR;
    String attributeName2 = attribute2.getName();
    AggregationType aggType2 = AggregationType.MIN;
    String resultAttributeName1 = AggregatorTestConstants.MAX_DATE_RESULT_ATTR_NAME;
    String resultAttributeName2 = AggregatorTestConstants.MIN_FIRST_NAME_RESULT_ATTR_NAME;
    AggregationAttributeAndResult aggEntity1 = new AggregationAttributeAndResult(attributeName1, aggType1, resultAttributeName1);
    AggregationAttributeAndResult aggEntity2 = new AggregationAttributeAndResult(attributeName2, aggType2, resultAttributeName2);
    List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>();
    aggEntitiesList.add(aggEntity1);
    aggEntitiesList.add(aggEntity2);
    IField[] row1 = { new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new StringField("Mary brown") };
    Schema schema = new Schema(new Attribute(resultAttributeName1, AttributeType.DATE), new Attribute(resultAttributeName2, AttributeType.STRING));
    List<Tuple> expectedResults = new ArrayList<>();
    expectedResults.add(new Tuple(schema, row1));
    List<Tuple> returnedResults = getQueryResults(aggEntitiesList);
    Assert.assertEquals(1, returnedResults.size());
    Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IField(edu.uci.ics.texera.api.field.IField) StringField(edu.uci.ics.texera.api.field.StringField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 47 with StringField

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

the class DictionaryManager method addDictionary.

public void addDictionary(String dictID, String dictionaryContent, String dictionaryName, String dictionaryDescription) throws StorageException {
    // write metadata info
    DataWriter dataWriter = relationManager.getTableDataWriter(DictionaryManagerConstants.TABLE_NAME);
    dataWriter.open();
    // clean up the same dictionary metadata if it already exists in dictionary table
    dataWriter.deleteTuple(new TermQuery(new Term(DictionaryManagerConstants.NAME, dictID)));
    // insert new tuple
    dataWriter.insertTuple(new Tuple(DictionaryManagerConstants.SCHEMA, new StringField(dictID)));
    dataWriter.close();
    // write actual dictionary file
    writeContentToFile(dictID, dictionaryContent);
    writeNameToFile(dictID, dictionaryName);
    writeDescriptionToFile(dictID, dictionaryDescription);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) StringField(edu.uci.ics.texera.api.field.StringField) Term(org.apache.lucene.index.Term) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Example 48 with StringField

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

the class PieChartSink method buildOtherNameField.

private IField buildOtherNameField() {
    Attribute nameColumn = inputOperator.getOutputSchema().getAttribute(predicate.getNameColumn());
    AttributeType nameColumnType = nameColumn.getType();
    if (nameColumnType.equals(AttributeType.STRING)) {
        return new StringField("Other");
    }
    return new TextField("Other");
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField)

Example 49 with StringField

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

the class WordCloudSink method processTuples.

@Override
public void processTuples() throws TexeraException {
    // calculate word frequencies
    List<Map.Entry<String, Integer>> wordCountList = wordCount();
    double minValue = Double.MAX_VALUE;
    double maxValue = Double.MIN_VALUE;
    for (Map.Entry<String, Integer> e : wordCountList) {
        int frequency = e.getValue();
        minValue = Math.min(minValue, frequency);
        maxValue = Math.max(maxValue, frequency);
    }
    // normalize the font size for wordcloud js
    // https://github.com/timdream/wordcloud2.js/issues/53
    List<Tuple> tempList = new ArrayList<>();
    for (Map.Entry<String, Integer> e : wordCountList) {
        int frequency = e.getValue();
        tempList.add(new Tuple(outputSchema, new StringField(e.getKey()), new IntegerField((int) ((frequency - minValue) / (maxValue - minValue) * (this.MAX_FONT_SIZE - this.MIN_FONT_SIZE) + this.MIN_FONT_SIZE))));
    }
    this.result = tempList;
}
Also used : IntegerField(edu.uci.ics.texera.api.field.IntegerField) StringField(edu.uci.ics.texera.api.field.StringField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 50 with StringField

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

the class PlanStore method updatePlanInternal.

/**
 * Updates both plan description and plan json of a plan with the given plan name.
 * If description is null, it will not update plan description.
 * If plan json is NULL, it will not update the plan's JSON file.
 *
 * @param planName, the name of the plan.
 * @param description, the new description of the plan.
 * @param logicalPlanJson, the new plan json string.
 * @throws TexeraException
 */
private void updatePlanInternal(String planName, String description, String logicalPlanJson) throws TexeraException {
    Tuple existingPlan = getPlan(planName);
    if (existingPlan == null) {
        return;
    }
    // Checking if an updated description or logical plan JSON string has been provided
    if (description == null && logicalPlanJson == null) {
        return;
    }
    // Checking if the logical plan JSON string needs to be updated
    if (logicalPlanJson != null) {
        // Compressing and checking the validity of the logical plan JSON string
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
            logicalPlanJson = objectMapper.writeValueAsString(jsonNode);
        } catch (IOException e) {
            throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson);
        }
    }
    // Getting the fields in order for performing the update
    IDField idField = (IDField) existingPlan.getField(SchemaConstants._ID);
    IField descriptionField = description != null ? new StringField(description) : existingPlan.getField(PlanStoreConstants.DESCRIPTION);
    IField logicalPlanJsonField = logicalPlanJson != null ? new StringField(logicalPlanJson) : existingPlan.getField(PlanStoreConstants.LOGICAL_PLAN_JSON);
    // Creating a tuple out of all the fields
    Tuple newTuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), descriptionField, logicalPlanJsonField);
    // Writing the updated tuple
    DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
    dataWriter.open();
    dataWriter.updateTuple(newTuple, idField);
    dataWriter.close();
}
Also used : IDField(edu.uci.ics.texera.api.field.IDField) StringField(edu.uci.ics.texera.api.field.StringField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) IField(edu.uci.ics.texera.api.field.IField) StorageException(edu.uci.ics.texera.api.exception.StorageException) Tuple(edu.uci.ics.texera.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Aggregations

StringField (edu.uci.ics.texera.api.field.StringField)103 Tuple (edu.uci.ics.texera.api.tuple.Tuple)94 IField (edu.uci.ics.texera.api.field.IField)87 IntegerField (edu.uci.ics.texera.api.field.IntegerField)87 TextField (edu.uci.ics.texera.api.field.TextField)79 Schema (edu.uci.ics.texera.api.schema.Schema)75 ArrayList (java.util.ArrayList)74 Test (org.junit.Test)70 Span (edu.uci.ics.texera.api.span.Span)64 DoubleField (edu.uci.ics.texera.api.field.DoubleField)63 DateField (edu.uci.ics.texera.api.field.DateField)60 Attribute (edu.uci.ics.texera.api.schema.Attribute)60 SimpleDateFormat (java.text.SimpleDateFormat)58 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)29 JoinDistancePredicate (edu.uci.ics.texera.dataflow.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 IDField (edu.uci.ics.texera.api.field.IDField)5 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)4