This is an automated email from the ASF dual-hosted git repository.
lupeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new c6c83dcd113 HBASE-23644 Thrift2 DemoClient.py is not running (#7530)
c6c83dcd113 is described below
commit c6c83dcd113b016efe5f38b4d75ba5cc7f9dceb8
Author: Liu Xiao <[email protected]>
AuthorDate: Thu Dec 18 22:03:42 2025 +0800
HBASE-23644 Thrift2 DemoClient.py is not running (#7530)
Signed-off-by: Peng Lu <[email protected]>
---
.../apache/hadoop/hbase/thrift2/DemoClient.java | 13 +--
hbase-examples/src/main/python/requirements.txt | 20 ++++
.../src/main/python/thrift2/DemoClient.py | 117 +++++++++++++--------
hbase-examples/src/main/resources/hbase-site.xml | 28 +++++
4 files changed, 128 insertions(+), 50 deletions(-)
diff --git
a/hbase-examples/src/main/java/org/apache/hadoop/hbase/thrift2/DemoClient.java
b/hbase-examples/src/main/java/org/apache/hadoop/hbase/thrift2/DemoClient.java
index fb6df302acc..2ed97a1207f 100644
---
a/hbase-examples/src/main/java/org/apache/hadoop/hbase/thrift2/DemoClient.java
+++
b/hbase-examples/src/main/java/org/apache/hadoop/hbase/thrift2/DemoClient.java
@@ -26,6 +26,7 @@ import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import javax.security.sasl.Sasl;
+import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.thrift2.generated.TColumnValue;
import org.apache.hadoop.hbase.thrift2.generated.TGet;
@@ -63,7 +64,7 @@ public class DemoClient {
if (args.length >= 2) {
port = Integer.parseInt(args[1]);
}
- org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
+ Configuration conf = HBaseConfiguration.create();
String principal = conf.get("hbase.thrift.kerberos.principal");
if (principal != null) {
secure = true;
@@ -140,12 +141,12 @@ public class DemoClient {
TResult result = client.get(table, get);
- System.out.print("row = " + ClientUtils.utf8(result.getRow()));
+ System.out.println("row = " + ClientUtils.utf8(result.getRow()));
for (TColumnValue resultColumnValue : result.getColumnValues()) {
- System.out.print("family = " +
ClientUtils.utf8(resultColumnValue.getFamily()));
- System.out.print("qualifier = " +
ClientUtils.utf8(resultColumnValue.getFamily()));
- System.out.print("value = " +
ClientUtils.utf8(resultColumnValue.getValue()));
- System.out.print("timestamp = " + resultColumnValue.getTimestamp());
+ System.out.println("family = " +
ClientUtils.utf8(resultColumnValue.getFamily()));
+ System.out.println("qualifier = " +
ClientUtils.utf8(resultColumnValue.getQualifier()));
+ System.out.println("value = " +
ClientUtils.utf8(resultColumnValue.getValue()));
+ System.out.println("timestamp = " + resultColumnValue.getTimestamp());
}
transport.close();
diff --git a/hbase-examples/src/main/python/requirements.txt
b/hbase-examples/src/main/python/requirements.txt
new file mode 100644
index 00000000000..5829eb363f1
--- /dev/null
+++ b/hbase-examples/src/main/python/requirements.txt
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+six==1.17.0
+thrift==0.14.1
diff --git a/hbase-examples/src/main/python/thrift2/DemoClient.py
b/hbase-examples/src/main/python/thrift2/DemoClient.py
index 720c3ae9c32..315edbc7ad7 100644
--- a/hbase-examples/src/main/python/thrift2/DemoClient.py
+++ b/hbase-examples/src/main/python/thrift2/DemoClient.py
@@ -1,21 +1,22 @@
#!/usr/bin/env python
"""
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
"""
+
# Instructions:
# 1. Run Thrift to generate the python module hbase
# thrift --gen py
../../../../../hbase-thrift/src/main/resources/org/apache/hadoop \
@@ -23,52 +24,80 @@
# 2. Create a directory of your choosing that contains:
# a. This file (DemoClient.py).
# b. The directory gen_py/hbase (generated by instruction step 1).
-# 3. pip install thrift==0.9.3
+# 3. pip install thrift==0.14.1
# 4. Create a table call "example", with a family called "family1" using the
hbase shell.
# 5. Start the hbase thrift2 server
# bin/hbase thrift2 start
# 6. Execute {python DemoClient.py}.
+import sys
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.protocol import TBinaryProtocol
from gen_py.hbase import THBaseService
from gen_py.hbase import ttypes
-print("Thrift2 Demo")
-print('This demo assumes you have a table called '
- '"example" with a column family called "family1"')
-host = "localhost"
-port = 9090
-framed = False
+def run(host, port, framed=False):
+
+ socket = TSocket.TSocket(host, port)
+ if framed:
+ transport = TTransport.TFramedTransport(socket)
+ else:
+ transport = TTransport.TBufferedTransport(socket)
+ protocol = TBinaryProtocol.TBinaryProtocol(transport)
+ client = THBaseService.Client(protocol)
+
+ transport.open()
+
+ # Check Thrift Server Type
+ serverType = client.getThriftServerType()
+ if serverType != ttypes.TThriftServerType.TWO:
+ raise RuntimeError(
+ f"Mismatch between client and server, server type is {serverType}"
+ )
+
+ table = "example".encode()
+
+ t_column_values = ttypes.TColumnValue(
+ family="family1".encode(),
+ qualifier="qualifier1".encode(),
+ value="value1".encode(),
+ )
+ put = ttypes.TPut(row="row1".encode(), columnValues=[t_column_values])
+ print("\nPutting:", put)
+ client.put(table, put)
-socket = TSocket.TSocket(host, port)
-if framed:
- transport = TTransport.TFramedTransport(socket)
-else:
- transport = TTransport.TBufferedTransport(socket)
-protocol = TBinaryProtocol.TBinaryProtocol(transport)
-client = THBaseService.Client(protocol)
+ get = ttypes.TGet(row="row1".encode())
+ print("\nGetting:", get)
+ result = client.get(table, get)
-transport.open()
+ print("\nResult:", result)
+ print(f"row = {result.row.decode()}")
+ for column_value in result.columnValues:
+ print(f"family = {column_value.family.decode()}")
+ print(f"qualifier = {column_value.qualifier.decode()}")
+ print(f"value = {column_value.value.decode()}")
+ print(f"timestamp = {column_value.timestamp}")
-# Check Thrift Server Type
-serverType = client.getThriftServerType()
-if serverType != ttypes.TThriftServerType.TWO:
- raise RuntimeError(f"Mismatch between client and server, server type is
{serverType}")
+ transport.close()
-table = "example"
-t_column_values =
ttypes.TColumnValue(family="family1",qualifier="qualifier1",value="value1")
-put = ttypes.TPut(row="row1", columnValues=[t_column_values])
-print("Putting:", put)
-client.put(table, put)
+if __name__ == "__main__":
+ print("Thrift2 Demo")
+ print("Usage: DemoClient [host=localhost] [port=9090]")
+ print(
+ "This demo assumes you have a table called "
+ '"example" with a column family called "family1"'
+ )
-get = ttypes.TGet(row="row1")
-print("Getting:", get)
-result = client.get(table, get)
+ default_host = "localhost"
+ default_port = 9090
+ is_framed_transport = False
-print("Result:", result)
+ if len(sys.argv) >= 2:
+ default_host = sys.argv[1]
+ if len(sys.argv) >= 3:
+ default_port = int(sys.argv[2])
-transport.close()
+ run(default_host, default_port, is_framed_transport)
diff --git a/hbase-examples/src/main/resources/hbase-site.xml
b/hbase-examples/src/main/resources/hbase-site.xml
new file mode 100644
index 00000000000..ab4d1cd0b73
--- /dev/null
+++ b/hbase-examples/src/main/resources/hbase-site.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<!--
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+-->
+<configuration>
+ <property>
+ <name>hbase.defaults.for.version.skip</name>
+ <value>true</value>
+ </property>
+</configuration>