From 0b2eb3594b0a464fca82057d282fff819327503a Mon Sep 17 00:00:00 2001 From: Sean Busbey Date: Fri, 21 Feb 2020 15:05:16 -0600 Subject: [PATCH] Revert "replaced deprecated code in Example Scala Code section" This reverts commit 4381b18b873c5813af561bf75e567bf4d2215da5. --- .../asciidoc/_chapters/external_apis.adoc | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/asciidoc/_chapters/external_apis.adoc b/src/main/asciidoc/_chapters/external_apis.adoc index 129094e1d1c..b7aebb46557 100644 --- a/src/main/asciidoc/_chapters/external_apis.adoc +++ b/src/main/asciidoc/_chapters/external_apis.adoc @@ -934,33 +934,35 @@ libraryDependencies ++= Seq( === Example Scala Code -This example lists HBase tables, creates a new table, adds a row to it, and gets the value of the row. +This example lists HBase tables, creates a new table, and adds a row to it. [source, scala] ---- -import org.apache.hadoop.hbase.{HBaseConfiguration, TableName} -import org.apache.hadoop.hbase.client.{Admin, Connection, ConnectionFactory, Get, Put} +import org.apache.hadoop.hbase.HBaseConfiguration +import org.apache.hadoop.hbase.client.{Connection,ConnectionFactory,HBaseAdmin,HTable,Put,Get} import org.apache.hadoop.hbase.util.Bytes -val conf = HBaseConfiguration.create() + +val conf = new HBaseConfiguration() val connection = ConnectionFactory.createConnection(conf); val admin = connection.getAdmin(); // list the tables -val listtables = admin.listTables() +val listtables=admin.listTables() listtables.foreach(println) // let's insert some data in 'mytable' and get the row -val table = connection.getTable(TableName.valueOf("mytable")) -val theput = new Put(Bytes.toBytes("rowkey1")) +val table = new HTable(conf, "mytable") -theput.addColumn(Bytes.toBytes("ids"),Bytes.toBytes("id1"),Bytes.toBytes("one")) +val theput= new Put(Bytes.toBytes("rowkey1")) + +theput.add(Bytes.toBytes("ids"),Bytes.toBytes("id1"),Bytes.toBytes("one")) table.put(theput) -val theget = new Get(Bytes.toBytes("rowkey1")) -val result = table.get(theget) -val value = result.value() +val theget= new Get(Bytes.toBytes("rowkey1")) +val result=table.get(theget) +val value=result.value() println(Bytes.toString(value)) ----