Skip to content

Commit

Permalink
Fix issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Cher committed Dec 13, 2012
1 parent c9ffd7a commit 60d5e4c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/main/java/hrider/data/ObjectType.java
Expand Up @@ -43,6 +43,10 @@ public enum ObjectType {
Xml,
Json;

//region Constants
private static final byte[] EMPTY_BYTES_ARRAY = new byte[0];
//endregion

//region Public Methods

/**
Expand Down Expand Up @@ -108,7 +112,7 @@ public Object toObject(String value) {
*/
public byte[] fromString(String value) {
if (value == null) {
return null;
return EMPTY_BYTES_ARRAY;
}

switch (this) {
Expand Down Expand Up @@ -186,7 +190,7 @@ public Object fromByteArray(byte[] value) {
*/
public byte[] fromObject(Object value) {
if (value == null) {
return null;
return EMPTY_BYTES_ARRAY;
}

switch (this) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/hrider/hbase/Operator.java
Expand Up @@ -31,10 +31,21 @@ public enum Operator {
Equal,
NotEqual,
GreaterOrEqual,
Greater;
Greater,
IsNull,
IsNotNull;

//region Public Methods

/**
* Indicates if the operator is an unary operator.
*
* @return True if the operator represents an unary operator or False otherwise.
*/
public boolean isUnary() {
return this == IsNull || this == IsNotNull;
}

/**
* Gets a filter according to the operator type.
* @return A filter to be used in query on hbase.
Expand All @@ -57,6 +68,10 @@ public CompareFilter.CompareOp toFilter() {
return CompareFilter.CompareOp.GREATER_OR_EQUAL;
case Greater:
return CompareFilter.CompareOp.GREATER;
case IsNull:
return CompareFilter.CompareOp.EQUAL;
case IsNotNull:
return CompareFilter.CompareOp.NOT_EQUAL;
default:
throw new IllegalArgumentException(String.format("The specified operator type '%s' is not supported.", this));
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/hrider/hbase/Query.java
Expand Up @@ -324,7 +324,12 @@ public byte[] getWordAsByteArray() {
* @param value A new value to set.
*/
public void setWord(String value) {
this.word = value;
if (value != null && !value.isEmpty()) {
this.word = value;
}
else {
this.word = null;
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/hrider/hbase/QueryScanner.java
Expand Up @@ -35,6 +35,7 @@ public class QueryScanner extends Scanner {
* A constant representing a size of the unicode character.
*/
private static final int UNICODE_CHAR_SIZE = 4;
private static final byte[] EMPTY_BYTES_ARRAY = new byte[0];
//endregion

//region Variables
Expand Down Expand Up @@ -110,7 +111,7 @@ protected Scan getScanner() throws IOException {
scan.setTimeRange(this.query.getStartDate().getTime(), this.query.getEndDate().getTime());
}

if (this.query.getWord() != null) {
if (this.query.getWord() != null || this.query.getOperator().isUnary()) {
WritableByteArrayComparable comparator;

switch (this.query.getOperator()) {
Expand All @@ -131,6 +132,10 @@ protected Scan getScanner() throws IOException {
case Greater:
comparator = new BinaryComparator(this.query.getWordAsByteArray());
break;
case IsNull:
case IsNotNull:
comparator = new BinaryComparator(EMPTY_BYTES_ARRAY);
break;
default:
throw new IllegalArgumentException(String.format("The specified operator type '%s' is not supported.", this.query.getOperator()));
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/hrider/ui/forms/ScanDialog.java
Expand Up @@ -142,17 +142,15 @@ public Query getQuery() {
query.setEndDate(this.endTimeDatePicker.getDate());
}

if (!this.textFieldWord.getText().trim().isEmpty()) {
String column = (String)this.comboBoxColumns.getSelectedItem();
String column = (String)this.comboBoxColumns.getSelectedItem();

String[] parts = column.split(":");
query.setFamily(parts[0]);
query.setColumn(parts[1]);
String[] parts = column.split(":");
query.setFamily(parts[0]);
query.setColumn(parts[1]);

query.setOperator((Operator)this.comboBoxOperator.getSelectedItem());
query.setWord(this.textFieldWord.getText().trim());
query.setWordType((ObjectType)this.comboBoxWordType.getSelectedItem());
}
query.setOperator((Operator)this.comboBoxOperator.getSelectedItem());
query.setWord(this.textFieldWord.getText().trim());
query.setWordType((ObjectType)this.comboBoxWordType.getSelectedItem());

return query;
}
Expand Down

0 comments on commit 60d5e4c

Please sign in to comment.