1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.hbql.statement;
22
23 import org.apache.hadoop.hbase.client.tableindexed.IndexSpecification;
24 import org.apache.hadoop.hbase.hbql.client.ExecutionResults;
25 import org.apache.hadoop.hbase.hbql.client.HBqlException;
26 import org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;
27 import org.apache.hadoop.hbase.util.Bytes;
28
29 public class DescribeIndexForTableStatement extends TableStatement implements ConnectionStatement {
30
31 private final String indexName;
32
33 public DescribeIndexForTableStatement(final String indexName, final String tableName) {
34 super(null, tableName);
35 this.indexName = indexName;
36 }
37
38 private String getIndexName() {
39 return this.indexName;
40 }
41
42 protected ExecutionResults execute(final HConnectionImpl conn) throws HBqlException {
43 return executeDescribe(conn, this.getIndexName(), this.getTableName());
44 }
45
46 static ExecutionResults executeDescribe(final HConnectionImpl conn,
47 final String indexName,
48 final String tableName) throws HBqlException {
49
50 final ExecutionResults retval = new ExecutionResults();
51
52 if (!conn.tableExists(tableName)) {
53 retval.out.println("Table not found: " + tableName);
54 }
55 else {
56
57 final IndexSpecification index = conn.getIndexForTable(indexName, tableName);
58
59 if (index == null) {
60 retval.out.println("Index " + indexName + " not found for table " + tableName);
61 }
62 else {
63 retval.out.println("Index: " + index.getIndexId());
64 final byte[][] columns = index.getIndexedColumns();
65 for (final byte[] column : columns)
66 retval.out.println("Index key: " + Bytes.toString(column));
67
68 final byte[][] otherColumns = index.getAdditionalColumns();
69 if (otherColumns.length > 0) {
70 retval.out.println("Additional columns in index: ");
71 for (final byte[] column : otherColumns)
72 retval.out.println(" " + Bytes.toString(column));
73 }
74 else {
75 retval.out.println("No additional columns in index.");
76 }
77 }
78 }
79 retval.out.flush();
80 return retval;
81 }
82
83 public static String usage() {
84 return "DESCRIBE INDEX index_name ON TABLE table_name";
85 }
86 }