Java Code Examples for org.apache.hadoop.hbase.util.Bytes.toByteArrays()

The following are Jave code examples for showing how to use toByteArrays() of the org.apache.hadoop.hbase.util.Bytes class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ditb   File: IndexQuerySQL.java   View Source Code Vote up 4 votes
/**
 * Construct from a sql sentence, such as "select * from table where f1:c1<'10' and f2:c1>'20'".
 *
 * @param querySql - sql query sentence
 */
public IndexQuerySQL(String querySql) {
  // check parameters passed from main function
  querySql = querySql.replace(",", " ").trim();
  String[] tempArray = querySql.split("[\\s]+");

  // check keyword "select"
  if (tempArray[0].compareToIgnoreCase("select") != 0) {
    throw new IllegalArgumentException("Keyword 'select' or 'SELECT' are not found!");
  }

  // get the position of keyword "from"
  int fromFlag = 0;
  for (fromFlag = 1; fromFlag < tempArray.length; fromFlag++) {
    if (tempArray[fromFlag].compareToIgnoreCase("from") == 0) break;
  }
  if (fromFlag >= tempArray.length) {
    throw new IllegalArgumentException("Keywords 'from' or 'FROM' are not found!");
  }

  // get selected columns contained in query result
  String[] tempColumns = new String[fromFlag - 1];
  for (int i = 1; i < fromFlag; i++) {
    tempColumns[i - 1] = tempArray[i];
  }
  if (tempColumns.length == 1 && tempColumns[0].equals("*")) {
    resultColumns = null;
  } else {
    resultColumns = Bytes.toByteArrays(tempColumns);
  }
  // get table name
  tableName = TableName.valueOf(tempArray[fromFlag + 1]);
  // check keyword "where"
  if (fromFlag + 2 < tempArray.length) {
    if (tempArray[fromFlag + 2].compareToIgnoreCase("where") != 0) {
      throw new IllegalArgumentException(
          "Keyword 'where' or 'WHERE' are not found or in the right position!");
    }
    // get query condition
    queryCondition = "";
    for (int i = fromFlag + 3; i < tempArray.length; i++) {
      queryCondition += tempArray[i] + " ";
    }
  } else {
    queryCondition = null;
  }

}