Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/sources/ddl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,26 @@ private[sql] case class CreateTableUsing(
}
}
val dataSource = clazz.newInstance().asInstanceOf[org.apache.spark.sql.sources.RelationProvider]
val relation = dataSource.createRelation(sqlContext, options)
val relation = dataSource.createRelation(sqlContext, new CaseInsensitiveMap(options))

sqlContext.baseRelationToSchemaRDD(relation).registerTempTable(tableName)
Seq.empty
}
}

/**
* Builds a map in which keys are case insensitive
*/
protected class CaseInsensitiveMap(map: Map[String, String]) extends Map[String, String] {

val baseMap = map.map(kv => kv.copy(_1 = kv._1.toLowerCase))

override def get(k: String): Option[String] = baseMap.get(k.toLowerCase)

override def + [B1 >: String](kv: (String, B1)): Map[String, B1] =
baseMap + kv.copy(_1 = kv._1.toLowerCase)

override def iterator: Iterator[(String, String)] = baseMap.iterator

override def -(key: String): Map[String, String] = baseMap - key.toLowerCase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import org.apache.spark.sql.catalyst.expressions.{Expression, Attribute}
*/
@DeveloperApi
trait RelationProvider {
/** Returns a new base relation with the given parameters. */
/**
* Returns a new base relation with the given parameters.
* Note: the parameters' keywords are case insensitive and this insensitivity is enforced
* by the Map that is passed to the function.
*/
def createRelation(sqlContext: SQLContext, parameters: Map[String, String]): BaseRelation
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SimpleScanSource extends RelationProvider {
override def createRelation(
sqlContext: SQLContext,
parameters: Map[String, String]): BaseRelation = {
SimpleScan(parameters("from").toInt, parameters("to").toInt)(sqlContext)
SimpleScan(parameters("from").toInt, parameters("TO").toInt)(sqlContext)
}
}

Expand All @@ -47,8 +47,8 @@ class TableScanSuite extends DataSourceTest {
|CREATE TEMPORARY TABLE oneToTen
|USING org.apache.spark.sql.sources.SimpleScanSource
|OPTIONS (
| from '1',
| to '10'
| From '1',
| To '10'
|)
""".stripMargin)
}
Expand Down