public class HiveStreamingConnection extends Object implements StreamingConnection
// create delimited record writer whose schema exactly matches table schema
StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
.withFieldDelimiter(',')
.build();
// create and open streaming connection (default.src table has to exist already)
StreamingConnection connection = HiveStreamingConnection.newBuilder()
.withDatabase("default")
.withTable("src")
.withAgentInfo("nifi-agent")
.withRecordWriter(writer)
.withHiveConf(hiveConf)
.connect();
// begin a transaction, write records and commit 1st transaction
connection.beginTransaction();
connection.write("key1,val1".getBytes());
connection.write("key2,val2".getBytes());
connection.commitTransaction();
// begin another transaction, write more records and commit 2nd transaction
connection.beginTransaction();
connection.write("key3,val3".getBytes());
connection.write("key4,val4".getBytes());
connection.commitTransaction();
// close the streaming connection
connection.close();
| Modifier and Type | Class and Description |
|---|---|
static class |
HiveStreamingConnection.Builder |
static class |
HiveStreamingConnection.TxnState |
| Modifier and Type | Method and Description |
|---|---|
void |
abortTransaction()
Manually abort the opened transaction.
|
void |
beginTransaction()
Begin a transaction for writing.
|
void |
close()
Close connection
|
void |
commitTransaction()
Commit a transaction to make the writes visible for readers.
|
PartitionInfo |
createPartitionIfNotExists(List<String> partitionValues)
Creates a partition if it does not exist.
|
String |
getAgentInfo()
Get agent info that is set during streaming connection.
|
ConnectionStats |
getConnectionStats()
Gets stats about the streaming connection.
|
HiveConf |
getHiveConf()
Returns hive configuration object used during connection creation.
|
String |
getMetastoreUri()
Get metastore URI that metastore client uses.
|
List<String> |
getStaticPartitionValues()
Get any static partitions specified during streaming connection creation.
|
Table |
getTable()
Get the table used by streaming connection.
|
boolean |
isDynamicPartitioning()
Get if dynamic partitioning is used.
|
boolean |
isPartitionedTable()
Get if the specified table is partitioned table or not.
|
static HiveStreamingConnection.Builder |
newBuilder() |
String |
toString() |
void |
write(byte[] record)
Write record using RecordWriter.
|
void |
write(InputStream inputStream)
Write record using RecordWriter.
|
public static HiveStreamingConnection.Builder newBuilder()
public PartitionInfo createPartitionIfNotExists(List<String> partitionValues) throws StreamingException
PartitionHandlercreatePartitionIfNotExists in interface PartitionHandlerpartitionValues - - partition valuesStreamingException - - any metastore related exceptionspublic void beginTransaction()
throws StreamingException
StreamingConnectionbeginTransaction in interface StreamingConnectionStreamingException - - if there are errors when beginning transactionpublic void commitTransaction()
throws StreamingException
StreamingConnectioncommitTransaction in interface StreamingConnectionStreamingException - - if there are errors when committing the open transactionpublic void abortTransaction()
throws StreamingException
StreamingConnectionabortTransaction in interface StreamingConnectionStreamingException - - if there are errors when aborting the transactionpublic void write(byte[] record)
throws StreamingException
StreamingConnectionwrite in interface StreamingConnectionrecord - - the data to be writtenStreamingException - - if there are errors when writingpublic void write(InputStream inputStream) throws StreamingException
StreamingConnectionwrite in interface StreamingConnectioninputStream - - input stream of recordsStreamingException - - if there are errors when writingpublic void close()
close in interface StreamingConnectionpublic ConnectionStats getConnectionStats()
StreamingConnectiongetConnectionStats in interface StreamingConnectionpublic HiveConf getHiveConf()
StreamingConnectiongetHiveConf in interface StreamingConnectionpublic String getMetastoreUri()
ConnectionInfogetMetastoreUri in interface ConnectionInfopublic Table getTable()
ConnectionInfogetTable in interface ConnectionInfopublic List<String> getStaticPartitionValues()
ConnectionInfogetStaticPartitionValues in interface ConnectionInfopublic String getAgentInfo()
ConnectionInfogetAgentInfo in interface ConnectionInfopublic boolean isPartitionedTable()
ConnectionInfoisPartitionedTable in interface ConnectionInfopublic boolean isDynamicPartitioning()
ConnectionInfoisDynamicPartitioning in interface ConnectionInfoCopyright © 2019 The Apache Software Foundation. All Rights Reserved.