use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.
the class JoinTestHelper method insertToTable.
public static void insertToTable(String tableName, List<Tuple> tuples) throws StorageException {
RelationManager relationManager = RelationManager.getRelationManager();
DataWriter outerDataWriter = relationManager.getTableDataWriter(tableName);
outerDataWriter.open();
for (Tuple tuple : tuples) {
outerDataWriter.insertTuple(tuple);
}
outerDataWriter.close();
}
use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.
the class DictionaryMatcherTestHelper method writeTestTables.
public static void writeTestTables() throws TextDBException {
RelationManager relationManager = RelationManager.getRelationManager();
// create the people table and write tuples
relationManager.createTable(PEOPLE_TABLE, "../index/test_tables/" + PEOPLE_TABLE, TestConstants.SCHEMA_PEOPLE, LuceneAnalyzerConstants.standardAnalyzerString());
DataWriter peopleDataWriter = relationManager.getTableDataWriter(PEOPLE_TABLE);
peopleDataWriter.open();
for (Tuple tuple : TestConstants.getSamplePeopleTuples()) {
peopleDataWriter.insertTuple(tuple);
}
peopleDataWriter.close();
// create the people table and write tuples in Chinese
relationManager.createTable(CHINESE_TABLE, "../index/test_tables/" + CHINESE_TABLE, TestConstantsChinese.SCHEMA_PEOPLE, LuceneAnalyzerConstants.chineseAnalyzerString());
DataWriter chineseDataWriter = relationManager.getTableDataWriter(CHINESE_TABLE);
chineseDataWriter.open();
for (Tuple tuple : TestConstantsChinese.getSamplePeopleTuples()) {
chineseDataWriter.insertTuple(tuple);
}
chineseDataWriter.close();
}
use of edu.uci.ics.textdb.storage.DataWriter in project textdb by TextDB.
the class JoinTestHelper method clearTestTables.
/**
* Clears the data of the inner and outer test tables.
* @throws TextDBException
*/
public static void clearTestTables() throws TextDBException {
RelationManager relationManager = RelationManager.getRelationManager();
DataWriter bookDataWriter = relationManager.getTableDataWriter(BOOK_TABLE);
bookDataWriter.open();
bookDataWriter.clearData();
bookDataWriter.close();
DataWriter innerNewsDataWriter = relationManager.getTableDataWriter(NEWS_TABLE_INNER);
innerNewsDataWriter.open();
innerNewsDataWriter.clearData();
innerNewsDataWriter.close();
DataWriter outerNewsDataWriter = relationManager.getTableDataWriter(NEWS_TABLE_OUTER);
outerNewsDataWriter.open();
outerNewsDataWriter.clearData();
outerNewsDataWriter.close();
}
use of edu.uci.ics.textdb.storage.DataWriter 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.storage.DataWriter 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();
}
Aggregations