Github user lukasz-antoniak commented on a diff in the pull request:
https://github.com/apache/bahir/pull/72#discussion_r238359229
--- Diff:
sql-streaming-mqtt/src/main/scala/org/apache/bahir/sql/streaming/mqtt/HDFSMQTTSourceProvider.scala
---
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bahir.sql.streaming.mqtt
+
+import java.util.Locale
+
+import org.eclipse.paho.client.mqttv3.{MqttClient, MqttConnectOptions}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SQLContext
+import org.apache.spark.sql.execution.streaming.Source
+import org.apache.spark.sql.sources.{DataSourceRegister,
StreamSourceProvider}
+import org.apache.spark.sql.types.{LongType, StringType, StructField,
StructType}
+
+import org.apache.bahir.utils.MQTTConfig
+
+/**
+ * The provider class for creating MQTT source.
+ * This provider throw IllegalArgumentException if 'brokerUrl' or 'topic'
parameter
+ * is not set in options.
+ */
+class HDFSMQTTSourceProvider extends StreamSourceProvider with
DataSourceRegister with Logging {
+
+ override def sourceSchema(sqlContext: SQLContext, schema:
Option[StructType],
+ providerName: String, parameters: Map[String, String]): (String,
StructType) = {
+ ("mqtt", HDFSMQTTSourceProvider.SCHEMA_DEFAULT)
+ }
+
+ override def createSource(sqlContext: SQLContext, metadataPath: String,
+ schema: Option[StructType], providerName: String, parameters:
Map[String, String]): Source = {
+
+ def e(s: String) = new IllegalArgumentException(s)
+
+ val caseInsensitiveParameter = parameters.map{case (key: String,
value: String) =>
+ key.toLowerCase(Locale.ROOT) -> value
+ }
+
+ val brokerUrl: String = getParameterValue(caseInsensitiveParameter,
MQTTConfig.brokerUrl, "")
--- End diff --
We already have a common function to parse configuration parameters, so I
would try to reuse/adopt it.
---