-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from caraml-dev/bayu/hbase
feat: add HBase SDK for serving
- Loading branch information
Showing
21 changed files
with
937 additions
and
131 deletions.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
caraml-store-serving/src/main/java/dev/caraml/serving/store/bigtable/BaseSchemaRegistry.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,65 @@ | ||
package dev.caraml.serving.store.bigtable; | ||
|
||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.LoadingCache; | ||
import com.google.protobuf.ByteString; | ||
import java.util.concurrent.ExecutionException; | ||
import org.apache.avro.generic.GenericDatumReader; | ||
import org.apache.avro.generic.GenericRecord; | ||
|
||
public abstract class BaseSchemaRegistry { | ||
protected LoadingCache<SchemaReference, GenericDatumReader<GenericRecord>> cache = null; | ||
|
||
protected static String COLUMN_FAMILY = "metadata"; | ||
protected static String QUALIFIER = "avro"; | ||
protected static String KEY_PREFIX = "schema#"; | ||
public static final int SCHEMA_REFERENCE_LENGTH = 4; | ||
|
||
public static class SchemaReference { | ||
private final String tableName; | ||
private final ByteString schemaHash; | ||
|
||
public SchemaReference(String tableName, ByteString schemaHash) { | ||
this.tableName = tableName; | ||
this.schemaHash = schemaHash; | ||
} | ||
|
||
public String getTableName() { | ||
return tableName; | ||
} | ||
|
||
public ByteString getSchemaHash() { | ||
return schemaHash; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = tableName.hashCode(); | ||
result = 31 * result + schemaHash.hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
SchemaReference that = (SchemaReference) o; | ||
|
||
if (!tableName.equals(that.tableName)) return false; | ||
return schemaHash.equals(that.schemaHash); | ||
} | ||
} | ||
|
||
public GenericDatumReader<GenericRecord> getReader(SchemaReference reference) { | ||
GenericDatumReader<GenericRecord> reader; | ||
try { | ||
reader = this.cache.get(reference); | ||
} catch (ExecutionException | CacheLoader.InvalidCacheLoadException e) { | ||
throw new RuntimeException(String.format("Unable to find Schema"), e); | ||
} | ||
return reader; | ||
} | ||
|
||
public abstract GenericDatumReader<GenericRecord> loadReader(SchemaReference reference); | ||
} |
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
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
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
Oops, something went wrong.