Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.datastax.spark.connector
import com.datastax.spark.connector.cql._
import org.apache.spark.SparkContext
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{StructField, StructType}

/** Provides Cassandra-specific methods on [[org.apache.spark.sql.DataFrame]] */
class DataFrameFunctions(dataFrame: DataFrame) extends Serializable {
Expand All @@ -26,7 +28,15 @@ class DataFrameFunctions(dataFrame: DataFrame) extends Serializable {
val protocolVersion = connector.
withClusterDo(_.getConfiguration.getProtocolOptions.getProtocolVersion)

val rawTable = TableDef.fromDataFrame(dataFrame, keyspaceName, tableName, protocolVersion)
val caseSensitive = sparkContext.getConf.getBoolean(SQLConf.CASE_SENSITIVE.key, false)
val schema = if(!caseSensitive) {
new StructType(
dataFrame.schema.fields.map(
field => StructField(field.name.toLowerCase, field.dataType, field.nullable)))
} else
dataFrame.schema

val rawTable = TableDef.fromDataFrame(schema, keyspaceName, tableName, protocolVersion)
val columnMapping = rawTable.columnByName

val columnNames = columnMapping.keys.toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.datastax.spark.connector.types.{ColumnType, CounterType}
import com.datastax.spark.connector.util.NameTools
import com.datastax.spark.connector.util.Quote._
import com.datastax.spark.connector.util.Logging
import org.apache.spark.sql.types.StructType

/** Abstract column / field definition.
* Common to tables and user-defined types */
Expand Down Expand Up @@ -217,12 +218,12 @@ object TableDef {
implicitly[ColumnMapper[T]].newTable(keyspaceName, tableName, protocolVersion)

def fromDataFrame(
dataFrame: DataFrame,
schema: StructType,
keyspaceName: String,
tableName: String,
protocolVersion: ProtocolVersion): TableDef =

new DataFrameColumnMapper(dataFrame.schema).newTable(keyspaceName, tableName, protocolVersion)
new DataFrameColumnMapper(schema).newTable(keyspaceName, tableName, protocolVersion)
}

/** A Cassandra keyspace metadata that can be serialized. */
Expand Down