Spark IoTDB Connecter

mvn clean scala:compile compile install

1. maven dependency

2. spark-shell user guide

  1. spark-shell --jars spark-iotdb-connector-0.10.0.jar,iotdb-jdbc-0.10.0-jar-with-dependencies.jar
  2. import org.apache.iotdb.spark.db._
  3. val df = spark.read.format("org.apache.iotdb.spark.db").option("url","jdbc:iotdb://127.0.0.1:6667/").option("sql","select * from root").load
  4. df.printSchema()
  5. df.show()

3. Schema Inference

The existing data in the TsFile is as follows:

You can also use narrow table form which as follows: (You can see part 4 about how to use narrow form)

4. Transform between wide and narrow table

  1. import org.apache.iotdb.spark.db._
  2. val wide_df = spark.read.format("org.apache.iotdb.spark.db").option("url", "jdbc:iotdb://127.0.0.1:6667/").option("sql", "select * from root where time < 1100 and time > 1000").load
  3. val narrow_df = Transformer.toNarrowForm(spark, wide_df)

5. Java user guide

  1. import org.apache.spark.sql.Dataset;
  2. import org.apache.spark.sql.Row;
  3. import org.apache.spark.sql.SparkSession;
  4. import org.apache.iotdb.spark.db.*
  5. public class Example {
  6. public static void main(String[] args) {
  7. .builder()
  8. .appName("Build a DataFrame from Scratch")
  9. .getOrCreate();
  10. Dataset<Row> df = spark.read().format("org.apache.iotdb.spark.db")
  11. .option("url","jdbc:iotdb://127.0.0.1:6667/")
  12. .option("sql","select * from root").load();
  13. df.printSchema();
  14. df.show();
  15. Dataset<Row> narrowTable = Transformer.toNarrowForm(spark, df)
  16. narrowTable.show()