MAVEN
<dependency>
<groupId>org.apache.kudu</groupId>
<artifactId>kudu-client</artifactId>
<version>1.7.0</version>
</dependency>
根据masters获取表
public static List< String> getKuduTableList ( String kuduMasters ) {
List< String> tableList = new ArrayList < String> ( ) ;
KuduClient client = new KuduClient. KuduClientBuilder ( kuduMasters) . build ( ) ;
try {
ListTablesResponse list = client. getTablesList ( ) ;
tableList = list. getTablesList ( ) ;
} catch ( Exception e) {
logger. error ( "kudu链接报错---------------" + e. getMessage ( ) ) ;
} finally {
try {
client. shutdown ( ) ;
} catch ( Exception e) {
e. printStackTrace ( ) ;
}
}
return tableList;
}
根据masters和tableName获取字段
public static List< Map< String, String>> getKuduColumnList ( String kuduMasters, String tableName ) {
KuduClient client = new KuduClient. KuduClientBuilder ( kuduMasters) . build ( ) ;
List< Map< String, String>> listMaps = new ArrayList < Map< String, String>> ( ) ;
try {
client. getTablesList ( ) ;
KuduTable table = client. openTable ( tableName) ;
Schema schema = table. getSchema ( ) ;
List< ColumnSchema> columns = schema. getColumns ( ) ;
for ( int i= 0 ; i< columns. size ( ) ; i++ ) {
ColumnSchema ob = columns. get ( i) ;
Map< String, String> map = new HashMap < String, String> ( ) ;
map. put ( ob. getName ( ) , ob. getType ( ) . getName ( ) ) ;
listMaps. add ( i, map) ;
}
} catch ( Exception e) {
e. printStackTrace ( ) ;
} finally {
try {
client. shutdown ( ) ;
} catch ( Exception e) {
e. printStackTrace ( ) ;
}
}
return listMaps;
}