commit a74867e58d6254dbf23b125d40ba155dcbfbba9e Author: Owen O'Malley Date: Thu Dec 19 08:58:54 2013 -0800 Add recordupdater diff --git ql/src/java/org/apache/hadoop/hive/ql/io/RecordUpdater.java ql/src/java/org/apache/hadoop/hive/ql/io/RecordUpdater.java new file mode 100644 index 0000000..41a8d76 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/io/RecordUpdater.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.io; + +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; + +import java.io.IOException; + +/** + * API for supporting updating records. + */ +public interface RecordUpdater + extends FSRecordWriter.StatsProvidingRecordWriter { + + /** + * Insert a new record into the table. + * @param currentTransaction the transaction id of the current transaction. + * @param bucket the bucket of the row + * @param row the row of data to insert + * @param inspector the object inspector for the row + * @throws IOException + */ + void insert(long currentTransaction, + int bucket, + Object row, + ObjectInspector inspector) throws IOException; + + /** + * Update an old record with a new set of values. + * @param currentTransaction the current transaction id + * @param originalTransaction the row's original transaction id + * @param originalBucket the row's original bucket id + * @param rowId the original row id + * @param row the new values for the row + * @param inspector the object inspector for the row + * @throws IOException + */ + void update(long currentTransaction, + long originalTransaction, + int originalBucket, + long rowId, + Object row, + ObjectInspector inspector) throws IOException; + + /** + * Delete a row from the table. + * @param currentTransaction the current transaction id + * @param originalTransaction the rows original transaction id + * @param originalBucket the row's original bucket id + * @param rowId the original row id + * @throws IOException + */ + void delete(long currentTransaction, + long originalTransaction, + int originalBucket, + long rowId) throws IOException; + + /** + * Flush the current set of rows to the underlying file system, so that + * they are available to readers. + * @throws IOException + */ + void flush() throws IOException; + + /** + * Close this updater. No further calls are legal after this. + * @param abort Can the data since the last flush be discarded? + * @throws IOException + */ + void close(boolean abort) throws IOException; +} diff --git ql/src/java/org/apache/hadoop/hive/ql/io/avro/UpdateReader.java ql/src/java/org/apache/hadoop/hive/ql/io/avro/UpdateReader.java new file mode 100644 index 0000000..1a7a326 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/io/avro/UpdateReader.java @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.io.avro; + +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; + +import java.io.IOException; + +/** + * A record reader that supports updates. It provides not only the row, but + * the unique identifier of (transaction id, bucket id, row id). This interface + * assumes the serde has already been applied to the row and that the + * deserialized object is the one returned instead of byte arrays. + */ +public interface UpdateReader { + + /** + * Advance to the next row and return it. + * @param row a row object that can be reused + * @return null if there are no more rows otherwise the new row + * @throws IOException + */ + Object next(Object row) throws IOException; + + /** + * Get the object inspector for the current row. + * @return the current row's object inspector + * @throws IOException + */ + ObjectInspector getObjectInspector() throws IOException; + + /** + * What was the original transaction id for the last row? + * @return the transaction id + * @throws IOException + */ + long getRowTransactionId() throws IOException; + + /** + * What was the original bucket id for the last row? + * @return the bucket id + * @throws IOException + */ + int getRowBucketId() throws IOException; + + /** + * What was the original row id for the last row? + * @return the row id + * @throws IOException + */ + long getRowId() throws IOException; + + /** + * What is the progress of the reader through the input? + * @return a number between 0.0 and 1.0 that represents the fraction of input + * that has been returned already. + * @throws IOException + */ + float getProgress() throws IOException; +}