com.nhncorp.neptune.client
Class NTable

java.lang.Object
  extended by com.nhncorp.neptune.client.NTable
All Implemented Interfaces:
com.nhncorp.neptune.common.Constants

public class NTable
extends java.lang.Object
implements com.nhncorp.neptune.common.Constants

NTable represents a table in Neptune and each table contains data of applications with distributed and persistent manner. This class provides applications with convenient way to handle its data, allowing applications to get and put the data as if they are located in local. NTable class is not thread safe, but it is permitted for each thread to own NTable instance and concurrently operate with it.


Field Summary
static int MAX_MULTI_ROW_RESULT
           
 
Fields inherited from interface com.nhncorp.neptune.common.Constants
BATCH_RECEIVER_SUCCESS, BATCH_UPLOAD, CHANGELOG_SERVER, COMPACTION, DELETEED, END_RECEIVE_ROW, GROUPS, INDEX_INTERVAL_LENGH, INSERTED, LOG_OP_ADD_COLUMN_VALUE, LOG_OP_CREATE_ROW, LOG_OP_DELETE_COLUMN_VALUE, LOG_OP_MODIFY_META, MAP_RECORD_COLUMN, MAP_RECORD_ROW, MASTER, MASTER_SERVER, MAX_KEY_LENGTH, MAX_VALUE, META_COLUMN_NAME_TABLETINFO, MIN_VALUE, NEPTUNE, OPEN_SCANNER, PATH_SCHEMA, PIPE_CL_FILE_NAME, PROCESS, ROOT_TABLET, SCANNER_END, SCANNER_OPEN_FAIL, SCANNER_OPEN_SUCCESS, SCHEMA_DESCRIPTION_FILE_NAME, SCHEMA_INFO_FILENAME, SERVER, SPLIT, SPLIT_INFO, SPLIT_STORE, SUPERGROUP, TABLE_DROP, TABLE_LOCK, TABLE_NAME_META, TABLE_NAME_ROOT, TABLET_ALIVE, TABLET_ASSIGN, TABLET_AVAIL, TABLET_CREATED, TABLET_DROP, TABLET_FAIL, TABLET_STOP_MARK, TABLETSERVER_SPLIT, TEST_MODE, UPLOAD_END, UPLOAD_FAIL, UPLOAD_START_ROW, UPLOADER, USERS
 
Method Summary
 void addColumn(java.lang.String addedColumnName)
          Append new column.
 TabletInfo addTablet(Row.Key endRowKey)
          Add new tablet in this table with the specified row key
static void createTable(NConfiguration conf, TableSchema tableSchema)
          Create a new table according to the table schema information
static void createTable(NConfiguration conf, TableSchema tableSchema, Row.Key[] endRowKeys)
          Create a new table according to the table schma information, then split the newly created table into multiple tablets by the number of row keys specified in the parameter.
 TableSchema descTable()
          Retrieve table schema information of this NTable instance
 void dropTable()
          Drop the table of this NTable instance.
static void dropTable(NConfiguration conf, java.lang.String tableName)
          Drop the table specified by the tableName parameter
static boolean existsTable(NConfiguration conf, java.lang.String tableName)
          Check if table exists.
 boolean get(java.util.Collection<Row.Key> rowKeys, java.util.List<CellFilter> cellFilters, AsyncDataReceiver dataReceiver, int numOfThread, int timeout)
          This method allows applications to asynchronously receive data.
 boolean get(java.util.Collection<Row.Key> rowKeys, java.lang.String[] columnNames, AsyncDataReceiver dataReceiver, int numOfThread, int timeout)
          This method allows applications to asynchronously receive data.
 Row get(Row.Key rowKey)
          Retrieve all the columns and their values in Row matching with rowKey If the Row contains too much data, it may cause serious problem.
 Row get(Row.Key rowKey, java.lang.String columnName)
          Retrieve data stored in Neptune
 Row get(Row.Key rowKey, java.lang.String[] columnNames)
          Retrieve data with row key and specific column names.
 byte[] get(Row.Key rowKey, java.lang.String columnName, Cell.Key cellKey)
          Retrive data the application stored by put method
 Row get(RowFilter rowFilter)
          Retrieve data stored in Neptune with a specific filter.
 java.lang.String[] getColumnsArray()
          Return column array
 NConfiguration getConf()
          Return Neptune configuration object.
 Row[] gets(RowFilter rowFilter)
          This method is different with other get methods in applying the operation to multiple rows.
 Row.Key[] getSplitedRowKeyRanges(TabletInfo tabletInfo, int splitPerTablet)
          Divides row keys contained in a certain tablet into splitPerTablet rows.
 java.lang.String getTableName()
          Return current table name.
 TableSchema getTableSchema()
          Return the table schema information describing this table.
 java.lang.String[] getTabletAllActions(TabletInfo tabletInfo)
          (Only for management) Retrieve the list of all the actions internally performed in specified tablet
 TabletInfo getTabletInfo(java.lang.String tabletName)
          Return the tablet information
 com.nhncorp.neptune.tablet.TabletReport getTabletReport(TabletInfo tabletInfo)
          (Only for management) Get the report of tablet, describing current status of specified tablet.
 boolean hasValue(java.lang.String columnName, Row.Key rowKey)
          Check whether a Row with parameter rowkey exists or not Instead, it is possible to use get() method, but it is not recommended due to performance reason
static TableSchema[] listTables(NConfiguration conf)
          Returns schema information of all the tables in Neptune
 TabletInfo[] listTabletInfos()
          Get the list of all the tablet information of this table.
static TabletInfo lookupTargetTablet(NConfiguration conf, java.lang.String tableName, Row.Key rowKey)
          Find a tablet serving a specified row and return its information
 TabletInfo lookupTargetTablet(Row.Key rowKey)
          Find a tablet serving a specified row and return its information
static void main(java.lang.String[] args)
           
 DirectUploader openDirectUploader(java.lang.String[] columnNames)
          Open new BatchUploader and return its instance.
static NTable openTable(NConfiguration conf, java.lang.String tableName)
          Returns NTable instance if exists, otherwise returns null.
static NTable openTable(NConfiguration conf, TableSchema tableSchema, boolean create)
          Returns NTable instance if exists, otherwise returns null.
 void put(Row row)
          Put Row data in this table.
 void put(Row row, boolean systemTimestamp)
          Put Row data in this table.
 void remove(Row.Key rowKey, java.lang.String columnName, Cell.Key cellKey)
          Remove a Cell in a Row
 void removeRow(Row.Key rowKey, long timestamp)
          Remove all cells in a row.
 void truncateColumn(java.lang.String columnName)
          Delete all the data of a column specified by columnName in this table.
 void truncateTable()
          Delete all the data contained in this table.
 void truncateTable(boolean clearPartitionInfo)
          Delete all the data contained in this table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_MULTI_ROW_RESULT

public static final int MAX_MULTI_ROW_RESULT
See Also:
Constant Field Values
Method Detail

openTable

public static NTable openTable(NConfiguration conf,
                               java.lang.String tableName)
                        throws java.io.IOException
Returns NTable instance if exists, otherwise returns null.

Parameters:
conf - Configuration variables of Neptune
tableName - table name
Returns:
NTable instance
Throws:
java.io.IOException

openTable

public static NTable openTable(NConfiguration conf,
                               TableSchema tableSchema,
                               boolean create)
                        throws java.io.IOException
Returns NTable instance if exists, otherwise returns null.

Parameters:
conf - Configuration variables of Neptune
tableSchema -
create - true, if you want to create a new table when it does not exist.
Returns:
NTable instance
Throws:
java.io.IOException

existsTable

public static boolean existsTable(NConfiguration conf,
                                  java.lang.String tableName)
                           throws java.io.IOException
Check if table exists.

Parameters:
conf - Configuration variables of Neptune
tableName - table name
Returns:
true if the table exists, otherwise false.
Throws:
java.io.IOException

listTables

public static TableSchema[] listTables(NConfiguration conf)
                                throws java.io.IOException
Returns schema information of all the tables in Neptune

Parameters:
conf - Configuration variables of Neptune
Returns:
TableInfo[] the list of all the table schema information
Throws:
java.io.IOException

put

public void put(Row row)
         throws java.io.IOException
Put Row data in this table.

Parameters:
row -
Throws:
java.io.IOException

put

public void put(Row row,
                boolean systemTimestamp)
         throws java.io.IOException
Put Row data in this table. If the parameter systemTimestamp is set as true, Neptune exploits system clock in TabletServer as an identifier of this Row object. Otherwise, the application has to assign the timestamp value in Row object by itself. In this case, the application must generate unique timestamp value to avoid data collisions.

Parameters:
row -
systemTimestamp - If true, use system timestamp. If false, use user timestamp and you must set timestamp in Cell.Value
Throws:
java.io.IOException

removeRow

public void removeRow(Row.Key rowKey,
                      long timestamp)
               throws java.io.IOException
Remove all cells in a row.

Parameters:
timestamp - When storing change logs of this delete operation, use this timestamp value
Throws:
java.io.IOException

remove

public void remove(Row.Key rowKey,
                   java.lang.String columnName,
                   Cell.Key cellKey)
            throws java.io.IOException
Remove a Cell in a Row

Parameters:
rowKey -
columnName -
cellKey -
Throws:
java.io.IOException

hasValue

public boolean hasValue(java.lang.String columnName,
                        Row.Key rowKey)
                 throws java.io.IOException
Check whether a Row with parameter rowkey exists or not Instead, it is possible to use get() method, but it is not recommended due to performance reason

Parameters:
columnName -
rowKey -
Returns:
returns true if there exists a row matching with rowkey, otherwise false
Throws:
java.io.IOException

get

public byte[] get(Row.Key rowKey,
                  java.lang.String columnName,
                  Cell.Key cellKey)
           throws java.io.IOException
Retrive data the application stored by put method

Parameters:
rowKey -
columnName -
cellKey -
Returns:
null, if there is no data associating with parameters
Throws:
java.io.IOException

get

public Row get(Row.Key rowKey)
        throws java.io.IOException
Retrieve all the columns and their values in Row matching with rowKey If the Row contains too much data, it may cause serious problem. Therefore, Neptune restricts the limit in transformation and IOException will be thrown if the limit exceeds.

Parameters:
rowKey -
Returns:
null, If there is no data matching with the row key
Throws:
java.io.IOException

get

public Row get(Row.Key rowKey,
               java.lang.String[] columnNames)
        throws java.io.IOException
Retrieve data with row key and specific column names.

Parameters:
rowKey -
columnNames -
Returns:
null, If there is no data matching with the row key
Throws:
java.io.IOException

get

public boolean get(java.util.Collection<Row.Key> rowKeys,
                   java.util.List<CellFilter> cellFilters,
                   AsyncDataReceiver dataReceiver,
                   int numOfThread,
                   int timeout)
            throws java.io.IOException
This method allows applications to asynchronously receive data. The invocation of this method is immediately returned after triggering data retrieval. The result of retrieval is returned through DataReceiver specified in the parameter. The retrieval is only valid within the timeout.

Parameters:
rowKeys -
cellFilters -
dataReceiver -
numOfThread -
timeout -
Throws:
java.io.IOException

get

public boolean get(java.util.Collection<Row.Key> rowKeys,
                   java.lang.String[] columnNames,
                   AsyncDataReceiver dataReceiver,
                   int numOfThread,
                   int timeout)
            throws java.io.IOException
This method allows applications to asynchronously receive data. The invocation of this method is immediately returned after triggering data retrieval. The result of retrieval is returned through DataReceiver specified in the parameter. The retrieval is only valid within the timeout.

Parameters:
rowKeys -
columnNames -
dataReceiver -
timeout -
Throws:
java.io.IOException

get

public Row get(Row.Key rowKey,
               java.lang.String columnName)
        throws java.io.IOException
Retrieve data stored in Neptune

Parameters:
rowKey -
columnName -
Returns:
null, If there is no data matching with the row key
Throws:
java.io.IOException

get

public Row get(RowFilter rowFilter)
        throws java.io.IOException
Retrieve data stored in Neptune with a specific filter. The filter contains the various conditions determining data to be retrieved to the client application This filter is not applied to multiple rows

Parameters:
rowFilter -
Returns:
null, If there is no data matching with the row key
Throws:
java.io.IOException

gets

public Row[] gets(RowFilter rowFilter)
           throws java.io.IOException
This method is different with other get methods in applying the operation to multiple rows. Also, convenient operations such as 'Like', 'Greater than' , 'Less than' are also supported.

Parameters:
rowFilter -
Returns:
null, If there is no data matching with the row key
Throws:
java.io.IOException

createTable

public static void createTable(NConfiguration conf,
                               TableSchema tableSchema)
                        throws java.io.IOException
Create a new table according to the table schema information

Parameters:
conf - Configuration variables of Neptune
tableSchema -
Throws:
java.io.IOException

createTable

public static void createTable(NConfiguration conf,
                               TableSchema tableSchema,
                               Row.Key[] endRowKeys)
                        throws java.io.IOException
Create a new table according to the table schma information, then split the newly created table into multiple tablets by the number of row keys specified in the parameter. Each row key value represents the end row key value of each divided tablet.

Parameters:
endRowKeys -
Throws:
java.io.IOException

dropTable

public static void dropTable(NConfiguration conf,
                             java.lang.String tableName)
                      throws java.io.IOException
Drop the table specified by the tableName parameter

Parameters:
conf - Configuration variables of Neptune
tableName - table name
Throws:
java.io.IOException

dropTable

public void dropTable()
               throws java.io.IOException
Drop the table of this NTable instance. All the data and files associated with the table are removed.

Throws:
java.io.IOException

truncateTable

public void truncateTable(boolean clearPartitionInfo)
                   throws java.io.IOException
Delete all the data contained in this table.

Parameters:
clearPartitionInfo - clear partition information if true.
Throws:
java.io.IOException

truncateTable

public void truncateTable()
                   throws java.io.IOException
Delete all the data contained in this table.

Throws:
java.io.IOException

truncateColumn

public void truncateColumn(java.lang.String columnName)
                    throws java.io.IOException
Delete all the data of a column specified by columnName in this table.

Parameters:
columnName -
Throws:
java.io.IOException

descTable

public TableSchema descTable()
                      throws java.io.IOException
Retrieve table schema information of this NTable instance

Returns:
If no tablet schema information, returns null
Throws:
java.io.IOException

addColumn

public void addColumn(java.lang.String addedColumnName)
               throws java.io.IOException
Append new column. There will be no changes of data contained by this table

Parameters:
addedColumnName -
Throws:
java.io.IOException

addTablet

public TabletInfo addTablet(Row.Key endRowKey)
                     throws java.io.IOException
Add new tablet in this table with the specified row key

Parameters:
tableName - table name
endRowKey -
Returns:
Throws:
java.io.IOException

listTabletInfos

public TabletInfo[] listTabletInfos()
                             throws java.io.IOException
Get the list of all the tablet information of this table.

Returns:
TabletInfo 목록
Throws:
java.io.IOException

openDirectUploader

public DirectUploader openDirectUploader(java.lang.String[] columnNames)
                                  throws java.io.IOException
Open new BatchUploader and return its instance.

Parameters:
columnNames -
Returns:
BatchUploader instance
Throws:
java.io.IOException

getTabletAllActions

public java.lang.String[] getTabletAllActions(TabletInfo tabletInfo)
                                       throws java.io.IOException
(Only for management) Retrieve the list of all the actions internally performed in specified tablet

Parameters:
tabletInfo -
Returns:
TabletAction의 class명
Throws:
java.io.IOException

getTabletReport

public com.nhncorp.neptune.tablet.TabletReport getTabletReport(TabletInfo tabletInfo)
                                                        throws java.io.IOException
(Only for management) Get the report of tablet, describing current status of specified tablet.

Parameters:
tabletInfo -
Returns:
TabletReport 정보, 해당 tablet에 대한 정보를 가져올 수 없는 경우 null 반환
Throws:
java.io.IOException

lookupTargetTablet

public TabletInfo lookupTargetTablet(Row.Key rowKey)
                              throws java.io.IOException
Find a tablet serving a specified row and return its information

Parameters:
rowKey -
Returns:
tablet information
Throws:
java.io.IOException

lookupTargetTablet

public static TabletInfo lookupTargetTablet(NConfiguration conf,
                                            java.lang.String tableName,
                                            Row.Key rowKey)
                                     throws java.io.IOException
Find a tablet serving a specified row and return its information

Parameters:
hashRow.Key -
Returns:
tablet information
Throws:
java.io.IOException

getTableName

public java.lang.String getTableName()
Return current table name.

Returns:

getConf

public NConfiguration getConf()
Return Neptune configuration object.

Returns:

getColumnsArray

public java.lang.String[] getColumnsArray()
                                   throws java.io.IOException
Return column array

Returns:
Throws:
java.io.IOException

getTabletInfo

public TabletInfo getTabletInfo(java.lang.String tabletName)
                         throws java.io.IOException
Return the tablet information

Parameters:
tabletName -
Returns:
Throws:
java.io.IOException

getTableSchema

public TableSchema getTableSchema()
Return the table schema information describing this table.

Returns:

getSplitedRowKeyRanges

public Row.Key[] getSplitedRowKeyRanges(TabletInfo tabletInfo,
                                        int splitPerTablet)
                                 throws java.io.IOException
Divides row keys contained in a certain tablet into splitPerTablet rows. This method is useful in MapReduce application. When multiple Map tasks perform their job from one tablet on MapReduce, the rows in the tablet should be distributed to the Map tasks. This method helps divide the range of rows to assign multiple Map tasks.

Parameters:
tabletInfo -
splitPerTablet -
Returns:
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception