This example applies only to MRS OpenTSDB.
A datasource connection has been created and bound to a queue on the DLI management console.
Hard-coded or plaintext passwords pose significant security risks. To ensure security, encrypt your passwords, store them in configuration files or environment variables, and decrypt them when needed.
1 2 3 4 5 | <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-sql_2.11</artifactId> <version>2.3.2</version> </dependency> |
1 | import org.apache.spark.sql.SparkSession; |
1 | sparkSession = SparkSession.builder().appName("datasource-opentsdb").getOrCreate(); |
1 | sparkSession.sql("create table opentsdb_new_test using opentsdb options('Host'='10.0.0.171:4242','metric'='ctopentsdb','tags'='city,location')"); |
1 | sparkSession.sql("insert into opentsdb_new_test values('Penglai', 'abc', '2021-06-30 18:00:00', 30.0)"); |
1 | sparkSession.sql("select * from opentsdb_new_test").show(); |
spark.driver.extraClassPath=/usr/share/extension/dli/spark-jar/datasource/opentsdb/*
spark.executor.extraClassPath=/usr/share/extension/dli/spark-jar/datasource/opentsdb/*
<dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-sql_2.11</artifactId> <version>2.3.2</version> </dependency>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import org.apache.spark.sql.SparkSession; public class java_mrs_opentsdb { private static SparkSession sparkSession = null; public static void main(String[] args) { //create a SparkSession session sparkSession = SparkSession.builder().appName("datasource-opentsdb").getOrCreate(); sparkSession.sql("create table opentsdb_new_test using opentsdb options('Host'='10.0.0.171:4242','metric'='ctopentsdb','tags'='city,location')"); //*****************************SQL module*********************************** sparkSession.sql("insert into opentsdb_new_test values('Penglai', 'abc', '2021-06-30 18:00:00', 30.0)"); System.out.println("Penglai new timestamp"); sparkSession.sql("select * from opentsdb_new_test").show(); sparkSession.close(); } } |