This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maysam Yabandeh
committed
May 14, 2012
1 parent
6bc70e3
commit 19f0a87
Showing
4 changed files
with
254 additions
and
52 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/java/com/yahoo/omid/client/ColumnFamilyAndQuantifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2011 Yahoo! Inc. All rights reserved. | ||
* | ||
* Licensed 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. See accompanying LICENSE file. | ||
*/ | ||
|
||
package com.yahoo.omid.client; | ||
|
||
//A wrapper for both column family and the qualifier | ||
//Make it easier to be used in maps and hash maps | ||
public class ColumnFamilyAndQuantifier { | ||
protected byte[] family; | ||
protected byte[] qualifier; | ||
protected Integer hash = null; | ||
ColumnFamilyAndQuantifier(byte[] f, byte[] q) { | ||
family = f; | ||
qualifier = q; | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof ColumnFamilyAndQuantifier) { | ||
ColumnFamilyAndQuantifier other = (ColumnFamilyAndQuantifier) o; | ||
if (family.length != other.family.length || qualifier.length != other.qualifier.length) | ||
return false; | ||
for (int i = 0; i < family.length; i++) | ||
if (family[i] != other.family[i]) | ||
return false; | ||
for (int i = 0; i < qualifier.length; i++) | ||
if (qualifier[i] != other.qualifier[i]) | ||
return false; | ||
return true; | ||
} | ||
return false; | ||
} | ||
@Override | ||
public int hashCode() { | ||
if (hash != null) | ||
return hash; | ||
int h = 0; | ||
h = computeHash(h, family); | ||
h = computeHash(h, qualifier); | ||
hash = h; | ||
return h; | ||
} | ||
private int computeHash(int hash, byte[] larray) { | ||
hash += larray.length; | ||
for (int i = 0; i < larray.length; i++) { | ||
hash += larray[i]; | ||
} | ||
return hash; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/com/yahoo/omid/client/MinVersionsSingleColumnFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Copyright (c) 2011 Yahoo! Inc. All rights reserved. | ||
* | ||
* Licensed 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. See accompanying LICENSE file. | ||
*/ | ||
|
||
package com.yahoo.omid.client; | ||
|
||
import java.io.DataInput; | ||
import java.io.DataOutput; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
|
||
import org.apache.hadoop.hbase.KeyValue; | ||
import org.apache.hadoop.hbase.filter.*; | ||
|
||
/** | ||
* Filter that sets both minTimestamp and minVersions | ||
* Assumes that there is only one column in the output | ||
* @maysam | ||
*/ | ||
public class MinVersionsSingleColumnFilter extends FilterBase { | ||
|
||
//read at least minVersions and go till reach startTime | ||
long startTime = 0; | ||
long endTime = Long.MAX_VALUE; | ||
int minVersions; | ||
|
||
int includedVersions; | ||
|
||
|
||
/** | ||
* Used during deserialization. Do not use otherwise. | ||
*/ | ||
public MinVersionsSingleColumnFilter() { | ||
super(); | ||
} | ||
|
||
public MinVersionsSingleColumnFilter(long startTime, long endTime, int minVersions) { | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.minVersions = minVersions; | ||
init(); | ||
} | ||
|
||
private void init() { | ||
includedVersions = 0; | ||
} | ||
|
||
@Override | ||
public ReturnCode filterKeyValue(KeyValue v) { | ||
long version = v.getTimestamp(); | ||
if (version >= endTime) | ||
return ReturnCode.SKIP; | ||
if (includedVersions < minVersions || version > startTime) { | ||
includedVersions++; | ||
return ReturnCode.INCLUDE; | ||
} | ||
return ReturnCode.NEXT_COL; | ||
} | ||
|
||
@Override | ||
public void readFields(DataInput in) throws IOException { | ||
this.startTime = in.readLong(); | ||
this.endTime = in.readLong(); | ||
this.minVersions = in.readInt(); | ||
init(); | ||
} | ||
|
||
@Override | ||
public void write(DataOutput out) throws IOException { | ||
out.writeLong(this.startTime); | ||
out.writeLong(this.endTime); | ||
out.writeInt(this.minVersions); | ||
} | ||
} | ||
|
Oops, something went wrong.