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));
}
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);
}
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");
}
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;
}
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();
}
Aggregations