use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class PlanStore method addPlan.
/**
* Adds a Logical Plan JSON to the plan store.
*
* @param planName, the name of the plan.
* @param description, the description of the plan.
* @param logicalPlanJson, the logical plan JSON string
* @Return IDField, the id field of the plan stored.
* @throws TextDBException, when there are null fields or the given name is invalid or there is an existing plan with same name.
*/
public IDField addPlan(String planName, String description, String logicalPlanJson) throws TextDBException {
if (planName == null || description == null || logicalPlanJson == null) {
throw new TextDBException("Arguments cannot be null when adding a plan");
}
if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) {
throw new TextDBException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen.");
}
if (getPlan(planName) != null) {
throw new TextDBException("A plan with the same name already exists");
}
try {
// Converting the JSON String to a JSON Node to minimize space usage and to check validity of JSON string
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);
}
Tuple tuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), new StringField(description), new StringField(logicalPlanJson));
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
IDField id = dataWriter.insertTuple(tuple);
dataWriter.close();
return id;
}
use of edu.uci.ics.textdb.api.field.IDField 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 TextDBException
*/
private void updatePlanInternal(String planName, String description, String logicalPlanJson) throws TextDBException {
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();
}
use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class PlanStore method deletePlan.
/**
* Removess a plan by given name from plan store.
*
* @param planName, the name of the plan.
* @throws TextDBException
*/
public void deletePlan(String planName) throws TextDBException {
Tuple plan = getPlan(planName);
if (plan == null) {
return;
}
IDField idField = (IDField) plan.getField(SchemaConstants._ID);
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
dataWriter.deleteTupleByID(idField);
dataWriter.close();
}
use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class NlpSplitTest method test2.
@Test
public void test2() throws TextDBException, ParseException {
TupleSourceOperator tupleSource = new TupleSourceOperator(NlpSplitTestConstants.getOneToManyTestTuple(), NlpSplitTestConstants.SPLIT_SCHEMA);
NlpSplitOperator sentence_list = new NlpSplitOperator(new NlpSplitPredicate(NLPOutputType.ONE_TO_MANY, NlpSplitTestConstants.TEXT, PropertyNameConstants.NLP_OUTPUT_TYPE));
TupleSink tupleSink = new TupleSink();
sentence_list.setInputOperator(tupleSource);
tupleSink.setInputOperator(sentence_list);
tupleSink.open();
List<Tuple> results = tupleSink.collectAllTuples();
tupleSink.close();
Assert.assertTrue(TestUtils.equals(NlpSplitTestConstants.getOneToManyResultTuple(), results));
Set<IDField> compset = new HashSet<IDField>();
for (Tuple result : results) {
Assert.assertFalse(compset.contains(result.getField(SchemaConstants._ID)));
compset.add(result.getField(SchemaConstants._ID));
}
}
use of edu.uci.ics.textdb.api.field.IDField in project textdb by TextDB.
the class SimilarityJoinTest method test1.
/*
* Tests the Similarity Join Predicate on two similar words:
* Donald J. Trump
* Donald Trump
* Under the condition of similarity (NormalizedLevenshtein) > 0.8, these two words should match.
*
*/
@Test
public void test1() throws TextDBException {
JoinTestHelper.insertToTable(NEWS_TABLE_OUTER, JoinTestConstants.getNewsTuples().get(0));
JoinTestHelper.insertToTable(NEWS_TABLE_INNER, JoinTestConstants.getNewsTuples().get(1));
String trumpRegex = "[Dd]onald.{1,5}[Tt]rump";
RegexMatcher regexMatcherInner = JoinTestHelper.getRegexMatcher(JoinTestHelper.NEWS_TABLE_INNER, trumpRegex, JoinTestConstants.NEWS_BODY);
RegexMatcher regexMatcherOuter = JoinTestHelper.getRegexMatcher(JoinTestHelper.NEWS_TABLE_OUTER, trumpRegex, JoinTestConstants.NEWS_BODY);
SimilarityJoinPredicate similarityJoinPredicate = new SimilarityJoinPredicate(JoinTestConstants.NEWS_BODY, 0.8);
List<Tuple> results = JoinTestHelper.getJoinDistanceResults(regexMatcherInner, regexMatcherOuter, similarityJoinPredicate, Integer.MAX_VALUE, 0);
Schema joinInputSchema = Utils.addAttributeToSchema(JoinTestConstants.NEWS_SCHEMA, SchemaConstants.SPAN_LIST_ATTRIBUTE);
Schema resultSchema = similarityJoinPredicate.generateOutputSchema(joinInputSchema, joinInputSchema);
List<Span> resultSpanList = Arrays.asList(new Span("inner_" + JoinTestConstants.NEWS_BODY, 5, 20, trumpRegex, "Donald J. Trump", -1), new Span("outer_" + JoinTestConstants.NEWS_BODY, 18, 30, trumpRegex, "Donald Trump", -1));
Tuple resultTuple = new Tuple(resultSchema, new IDField(UUID.randomUUID().toString()), new IntegerField(2), new TextField("Alternative Facts and the Costs of Trump-Branded Reality"), new TextField("When Donald J. Trump swore the presidential oath on Friday, he assumed " + "responsibility not only for the levers of government but also for one of " + "the United States’ most valuable assets, battered though it may be: its credibility. " + "The country’s sentimental reverence for truth and its jealously guarded press freedoms, " + "while never perfect, have been as important to its global standing as the strength of " + "its military and the reliability of its currency. It’s the bedrock of that " + "American exceptionalism we’ve heard so much about for so long."), new IntegerField(1), new TextField("UCI marchers protest as Trump begins his presidency"), new TextField("a few hours after Donald Trump was sworn in Friday as the nation’s 45th president, " + "a line of more than 100 UC Irvine faculty members and students took to the campus " + "in pouring rain to demonstrate their opposition to his policies on immigration and " + "other issues and urge other opponents to keep organizing during Trump’s presidency."), new ListField<>(resultSpanList));
Assert.assertTrue(TestUtils.equals(Arrays.asList(resultTuple), results));
}
Aggregations