Skip to content

Commit 8aa81bf

Browse files
author
jackylk
committed
fix doc
1 parent 16bc463 commit 8aa81bf

File tree

5 files changed

+60
-60
lines changed

5 files changed

+60
-60
lines changed

examples/spark-hbase-demo1.md

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,25 @@
1-
## Example 1: Create and query SparkSQL table map to a new HBase table (multiple columns map to hbase table rowkey)
2-
In this example, we create a new SparkSQL table and map it to a new HBase table with multiple column in rowkey.
1+
## Example 2: Create and query SparkSQL table map to existing Hbase table
2+
In this example, we create SparkSQL table and map it to a existing HBase table. (a single column map to hbase rowkey)
33

44
Steps:
5-
6-
(1) Create table in hbase-sql shell:
7-
```
8-
$SPARK_HBASE_Home/bin/hbase-sql
9-
CREATE TABLE teacher(grade int, class int, subject string, teacher_name string, teacher_age int, PRIMARY KEY (grade, class, subject)) MAPPED BY (hbase_teacher, COLS=[teacher_name=teacher.name, teacher_age=teacher.age]);
5+
(1) Create table and populate data in HBase shell
106
```
7+
$HBase_Home/bin/hbase shell
8+
create 'hbase_numbers', 'f'
9+
for i in '1'..'100' do for j in '1'..'2' do put 'hbase_numbers', "row#{i}", "f:c#{j}", "#{i}#{j}" end end
10+
```
1111

12-
This command will create following tables:
13-
Tables :
14-
15-
spark : teacher
16-
17-
hbase : hbase_teacher
18-
19-
Fields :
20-
21-
[grade,int]
22-
23-
[class,int]
24-
25-
[subject,string]
26-
27-
[teacher_name,string]
28-
29-
[teacher_age,int]
30-
31-
key columns : grade,class,subject
32-
non-key colums: teacher_name, teacher_age
33-
34-
(2) Load data from a csv data file:
12+
(2) Map hbase table with sparksql table in hbase-sql shell
3513
```
36-
LOAD DATA INPATH './examples/teacher1k.csv' INTO TABLE teacher FIELDS TERMINATED BY "," ;
14+
$SPARK_HBASE_Home/bin/hbase-sql
15+
CREATE TABLE numbers(rowkey STRING, a STRING, b STRING, PRIMARY KEY (rowkey)) MAPPED BY (hbase_numbers, COLS=[a=f.c1, b=f.c2]);
3716
```
3817

39-
(3) Query :
18+
(3) Query:
4019
```
41-
// test where
42-
(1) select teacher_name,teacher_age from teacher where teacher_age > 25;
43-
44-
// test like in
45-
(2) select teacher_name,teacher_age,subject from teacher where teacher_name is not null and teacher_name like 'teacher_2_3%' and teacher_age not in (20,21,22,23,24,25)
46-
47-
// test subquery
48-
(3) select t1.teacher_name,t1.teacher_age from (select * from teacher where teacher_name like 'teacher_2_3%') t1 where t1.teacher_age < 25
49-
50-
//test group by
51-
(4) select teacher_name, sum(teacher_age) from teacher where grade=1 group by teacher_name
20+
// test count *
21+
(1) select count(*) from numbers
5222
53-
//test join
54-
(5) select t1.teacher_name, t2.subject, t1.teacher_age from (select teacher_name, teacher_age from teacher where teacher_age >=26 ) t1 join (select teacher_name, subject from teacher where teacher_name like 'teacher_2_3%')t2 on t1.teacher_name=t2.teacher_name
23+
// test group by
24+
(2) select a, b from numbers where b > "980"
5525
```

examples/spark-hbase-demo2.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
1-
## Example 2: Create and query SparkSQL table map to existing Hbase table
2-
In this example, we create SparkSQL table and map it to a existing HBase table. (a single column map to hbase rowkey)
1+
## Example 1: Create and query SparkSQL table map to a new HBase table (multiple columns map to hbase table rowkey)
2+
In this example, we create a new SparkSQL table and map it to a new HBase table with multiple column in rowkey.
33

44
Steps:
5-
(1) Create table and populate data in HBase shell
6-
```
7-
$HBase_Home/bin/hbase shell
8-
create 'hbase_numbers', 'f'
9-
for i in '1'..'100' do for j in '1'..'2' do put 'hbase_numbers', "row#{i}", "f:c#{j}", "#{i}#{j}" end end
10-
```
115

12-
(2) Map hbase table with sparksql table in hbase-sql shell
6+
(1) Create table in hbase-sql shell:
137
```
148
$SPARK_HBASE_Home/bin/hbase-sql
15-
CREATE TABLE numbers(rowkey STRING, a STRING, b STRING, PRIMARY KEY (rowkey)) MAPPED BY (hbase_numbers, COLS=[a=f.c1, b=f.c2]);
9+
CREATE TABLE teacher(grade int, class int, subject string, teacher_name string, teacher_age int, PRIMARY KEY (grade, class, subject)) MAPPED BY (hbase_teacher, COLS=[teacher_name=teacher.name, teacher_age=teacher.age]);
10+
```
11+
12+
This command will create following tables:
13+
Tables :
14+
15+
spark : teacher
16+
17+
hbase : hbase_teacher
18+
19+
Fields :
20+
21+
[grade,int]
22+
23+
[class,int]
24+
25+
[subject,string]
26+
27+
[teacher_name,string]
28+
29+
[teacher_age,int]
30+
31+
key columns : grade,class,subject
32+
non-key colums: teacher_name, teacher_age
33+
34+
(2) Load data from a csv data file:
35+
```
36+
LOAD DATA INPATH './examples/teacher1k.csv' INTO TABLE teacher FIELDS TERMINATED BY "," ;
1637
```
1738

18-
(3) Query:
39+
(3) Query :
1940
```
20-
// test count *
21-
(1) select count(*) from numbers
41+
// test where
42+
(1) select teacher_name,teacher_age from teacher where teacher_age > 25;
43+
44+
// test like in
45+
(2) select teacher_name,teacher_age,subject from teacher where teacher_name is not null and teacher_name like 'teacher_2_3%' and teacher_age not in (20,21,22,23,24,25)
46+
47+
// test subquery
48+
(3) select t1.teacher_name,t1.teacher_age from (select * from teacher where teacher_name like 'teacher_2_3%') t1 where t1.teacher_age < 25
49+
50+
//test group by
51+
(4) select teacher_name, sum(teacher_age) from teacher where grade=1 group by teacher_name
2252
23-
// test group by
24-
(2) select a, b from numbers where b > "980"
53+
//test join
54+
(5) select t1.teacher_name, t2.subject, t1.teacher_age from (select teacher_name, teacher_age from teacher where teacher_age >=26 ) t1 join (select teacher_name, subject from teacher where teacher_name like 'teacher_2_3%')t2 on t1.teacher_name=t2.teacher_name
2555
```
-8 Bytes
Binary file not shown.
Binary file not shown.
-16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)