Skip to content

create_table; region_locator; table_descriptor #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: hbase_compat_3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/com/alipay/oceanbase/hbase/OHTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ public Configuration getConfiguration() {
}

@Override
public HTableDescriptor getTableDescriptor() {
throw new FeatureNotSupportedException("not supported yet.");
public HTableDescriptor getTableDescriptor() throws IOException {
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableNameString, obTableClient);
return executor.getTableDescriptor();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public RegionLocator getRegionLocator(TableName tableName) throws IOException {
// to avoid change the database in original param url by namespace in tableName
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
ObTableClient obTableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(obTableClient);
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(tableName.toString(), obTableClient);
return executor.getRegionLocator(String.valueOf(tableName));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*-
* #%L
* OBKV HBase Client Framework
* %%
* Copyright (C) 2025 OceanBase Group
* %%
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* #L%
*/

package com.alipay.oceanbase.hbase.util;

import com.alibaba.fastjson.JSON;
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
import com.alipay.oceanbase.rpc.ObTableClient;
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;

import java.io.IOException;
import java.util.*;

public class OHCreateTableExecutor extends AbstractObTableMetaExecutor<Void> {
private final ObTableClient client;

OHCreateTableExecutor(ObTableClient client) {
this.client = client;
}

@Override
public ObTableRpcMetaType getMetaType() {
return ObTableRpcMetaType.HTABLE_CREATE_TABLE;
}

@Override
public Void parse(ObTableMetaResponse response) throws IOException {
// success, do nothing

return null;
}

public void createTable(HTableDescriptor tableDescriptor, byte[][] splitKeys) throws IOException {
final ObTableMetaRequest request = new ObTableMetaRequest();
request.setMetaType(getMetaType());
Map<String, Object> requestData = new HashMap<>();
requestData.put("htable_name", tableDescriptor.getTableName().getName());
Map<String, Map<String, Integer>> columnFamilies = new HashMap<>();
for (HColumnDescriptor columnDescriptor : tableDescriptor.getFamilies()) {
Map<String, Integer> columnFamily = new HashMap<>();
columnFamily.put("ttl", columnDescriptor.getTimeToLive());
columnFamily.put("max_version", columnDescriptor.getMaxVersions());
columnFamilies.put(columnDescriptor.getNameAsString(), columnFamily);
}
requestData.put("column_families", columnFamilies);
String jsonData = JSON.toJSONString(requestData);
request.setData(jsonData);
execute(client, request);
}
}
41 changes: 31 additions & 10 deletions src/main/java/com/alipay/oceanbase/hbase/util/OHRegionLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,44 @@
import java.util.List;

public class OHRegionLocator implements RegionLocator {
public OHRegionLocator(byte[][] startKeys, byte[][] endKeys) {

private byte[][] startKeys;
private byte[][] endKeys;
private TableName tableName;

private List<HRegionLocation> regionLocations;

public OHRegionLocator(byte[][] startKeys, byte[][] endKeys, List<HRegionLocation> regionLocations) {
this.startKeys = startKeys;
this.endKeys = endKeys;
this.regionLocations = regionLocations;
}

@Override
public HRegionLocation getRegionLocation(byte[] bytes) throws IOException {
// check if bytes is in the range of startKeys and endKeys
for (HRegionLocation regionLocation : regionLocations) {
if (regionLocation.getRegionInfo().containsRow(bytes)) {
return regionLocation;
}
}
return null;
}

@Override
public HRegionLocation getRegionLocation(byte[] bytes, boolean b) throws IOException {
return null;
if (b) {
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(tableName.toString(), tableClient);
RegionLocator location = executor.getRegionLocator(tableName.toString());
this.startKeys = location.getStartKeys();
this.endKeys = location.getEndKeys();
this.regionLocations = location.getAllRegionLocations();
}
return getRegionLocation(bytes);
}

@Override
public List<HRegionLocation> getAllRegionLocations() throws IOException {
return Collections.emptyList();
return regionLocations;
}

/**
Expand All @@ -40,7 +61,7 @@ public List<HRegionLocation> getAllRegionLocations() throws IOException {
*/
@Override
public byte[][] getStartKeys() throws IOException {
return null;
return startKeys;
}

/**
Expand All @@ -53,7 +74,7 @@ public byte[][] getStartKeys() throws IOException {
*/
@Override
public byte[][] getEndKeys() throws IOException {
return null;
return endKeys;
}

/**
Expand All @@ -67,18 +88,18 @@ public byte[][] getEndKeys() throws IOException {
*/
@Override
public Pair<byte[][], byte[][]> getStartEndKeys() throws IOException {
return null;
return Pair.newPair(startKeys, endKeys);
}

@Override
public TableName getName() {
return null;
return tableName;
}

private ObTableClient tableClient;

@Override
public void close() throws IOException {

return;
}
}
}
Loading