2016-06-03 6 views
1

ich einen Datenrahmen haben, enthält das Schema ein Array [Zeichenfolge] Feld:schreiben Spark-Datenrahmen zu Rotverschiebung: sparen StructField (user_agent, arraytype (String, true), true)

StructField("user_agent", ArrayType apply (StringType, true)) 

    ... 
    myDataframe.printSchema 
(an excerpt) 
|-- user_agent: array (nullable = true) 
| |-- element: string (containsNull = true) 

I com verwende. databricks.spark.redshift Paket um Redshift zu schreiben. Ich erhalte einen Fehler:

java.lang.IllegalArgumentException: Don't know how to save StructField(user_agent,ArrayType(StringType,true),true) to JDBC 
     at com.databricks.spark.redshift.JDBCWrapper$$anonfun$schemaString$1.apply(RedshiftJDBCWrapper.scala:253) 
     at com.databricks.spark.redshift.JDBCWrapper$$anonfun$schemaString$1.apply(RedshiftJDBCWrapper.scala:233) 

Ist es möglich, einen solchen Datentyp mit diesem Paket in Redshift zu schreiben?

+0

I hatte das gleiche Problem und das Array in einen String Umwandlung endete. –

Antwort

0

Funken Rotverschiebung unterstützt die folgenden Datentypen:

field.dataType match { 
      case IntegerType => "INTEGER" 
      case LongType => "BIGINT" 
      case DoubleType => "DOUBLE PRECISION" 
      case FloatType => "REAL" 
      case ShortType => "INTEGER" 
      case ByteType => "SMALLINT" // Redshift does not support the BYTE type. 
      case BooleanType => "BOOLEAN" 
      case StringType => 
      if (field.metadata.contains("maxlength")) { 
       s"VARCHAR(${field.metadata.getLong("maxlength")})" 
      } else { 
       "TEXT" 
      } 
      case TimestampType => "TIMESTAMP" 
      case DateType => "DATE" 
      case t: DecimalType => s"DECIMAL(${t.precision},${t.scale})" 
      case _ => throw new IllegalArgumentException(s"Don't know how to save $field to JDBC") 
} 

Source