Search in sources :

Example 21 with DataWriter

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

Example 22 with DataWriter

use of edu.uci.ics.texera.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 TexeraException, 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 TexeraException {
    if (planName == null || description == null || logicalPlanJson == null) {
        throw new TexeraException("Arguments cannot be null when adding a plan");
    }
    if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) {
        throw new TexeraException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen.");
    }
    if (getPlan(planName) != null) {
        throw new TexeraException("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;
}
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) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) StorageException(edu.uci.ics.texera.api.exception.StorageException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Example 23 with DataWriter

use of edu.uci.ics.texera.storage.DataWriter in project textdb by TextDB.

the class AggregatorTest method setUp.

@BeforeClass
public static void setUp() throws TexeraException {
    RelationManager relationManager = RelationManager.getInstance();
    // create the people table and write tuples
    relationManager.createTable(PEOPLE_TABLE, TestUtils.getDefaultTestIndex().resolve(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();
}
Also used : Tuple(edu.uci.ics.texera.api.tuple.Tuple) RelationManager(edu.uci.ics.texera.storage.RelationManager) DataWriter(edu.uci.ics.texera.storage.DataWriter) BeforeClass(org.junit.BeforeClass)

Example 24 with DataWriter

use of edu.uci.ics.texera.storage.DataWriter in project textdb by TextDB.

the class WordCountTest method setUp.

@BeforeClass
public static void setUp() throws TexeraException {
    cleanUp();
    RelationManager relationManager = RelationManager.getInstance();
    // Create the people table and write tuples
    relationManager.createTable(COUNT_TABLE, TestUtils.getDefaultTestIndex().resolve(COUNT_TABLE), TestConstants.SCHEMA_PEOPLE, LuceneAnalyzerConstants.standardAnalyzerString());
    DataWriter dataWriter = relationManager.getTableDataWriter(COUNT_TABLE);
    dataWriter.open();
    for (Tuple tuple : TestConstants.getSamplePeopleTuples()) {
        dataWriter.insertTuple(tuple);
    }
    dataWriter.close();
    expectedResult = computeExpectedResult(TestConstants.getSamplePeopleTuples(), TestConstants.DESCRIPTION, LuceneAnalyzerConstants.getStandardAnalyzer());
    relationManager.createTable(COUNT_CHINESE_TABLE, TestUtils.getDefaultTestIndex().resolve(COUNT_CHINESE_TABLE), TestConstantsChineseWordCount.SCHEMA_PEOPLE, LuceneAnalyzerConstants.chineseAnalyzerString());
    DataWriter dataWriterChinese = relationManager.getTableDataWriter(COUNT_CHINESE_TABLE);
    dataWriterChinese.open();
    for (Tuple tuple : TestConstantsChineseWordCount.getSamplePeopleTuples()) {
        dataWriterChinese.insertTuple(tuple);
    }
    dataWriterChinese.close();
    expectedResultChinese = computeExpectedResult(TestConstantsChineseWordCount.getSamplePeopleTuples(), TestConstantsChineseWordCount.DESCRIPTION, LuceneAnalyzerConstants.getLuceneAnalyzer(LuceneAnalyzerConstants.chineseAnalyzerString()));
}
Also used : Tuple(edu.uci.ics.texera.api.tuple.Tuple) RelationManager(edu.uci.ics.texera.storage.RelationManager) DataWriter(edu.uci.ics.texera.storage.DataWriter) BeforeClass(org.junit.BeforeClass)

Example 25 with DataWriter

use of edu.uci.ics.texera.storage.DataWriter in project textdb by TextDB.

the class ProjectionOperatorTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    RelationManager relationManager = RelationManager.getInstance();
    // create the people table and write tuples
    relationManager.createTable(PEOPLE_TABLE, TestUtils.getDefaultTestIndex().resolve(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();
}
Also used : Tuple(edu.uci.ics.texera.api.tuple.Tuple) RelationManager(edu.uci.ics.texera.storage.RelationManager) DataWriter(edu.uci.ics.texera.storage.DataWriter) BeforeClass(org.junit.BeforeClass)

Aggregations

DataWriter (edu.uci.ics.texera.storage.DataWriter)37 Tuple (edu.uci.ics.texera.api.tuple.Tuple)33 RelationManager (edu.uci.ics.texera.storage.RelationManager)19 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 BeforeClass (org.junit.BeforeClass)8 StorageException (edu.uci.ics.texera.api.exception.StorageException)3 IDField (edu.uci.ics.texera.api.field.IDField)3 StringField (edu.uci.ics.texera.api.field.StringField)3 IOException (java.io.IOException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Term (org.apache.lucene.index.Term)2 TermQuery (org.apache.lucene.search.TermQuery)2 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 IField (edu.uci.ics.texera.api.field.IField)1 TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)1 TupleSinkPredicate (edu.uci.ics.texera.dataflow.sink.tuple.TupleSinkPredicate)1 TwitterJsonConverter (edu.uci.ics.texera.dataflow.twitter.TwitterJsonConverter)1 TwitterJsonConverterPredicate (edu.uci.ics.texera.dataflow.twitter.TwitterJsonConverterPredicate)1