Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 98134200D0F for ; Fri, 29 Sep 2017 11:04:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 966941609ED; Fri, 29 Sep 2017 09:04:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DA57A1609C5 for ; Fri, 29 Sep 2017 11:04:05 +0200 (CEST) Received: (qmail 5370 invoked by uid 500); 29 Sep 2017 09:04:04 -0000 Mailing-List: contact issues-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@spark.apache.org Received: (qmail 5356 invoked by uid 99); 29 Sep 2017 09:04:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Sep 2017 09:04:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 6E9F51A21CD for ; Fri, 29 Sep 2017 09:04:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 1ZU4THbA1ati for ; Fri, 29 Sep 2017 09:04:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id D49935F3CE for ; Fri, 29 Sep 2017 09:04:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4EAD0E0E18 for ; Fri, 29 Sep 2017 09:04:02 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id BE66C242B1 for ; Fri, 29 Sep 2017 09:04:01 +0000 (UTC) Date: Fri, 29 Sep 2017 09:04:01 +0000 (UTC) From: "yzheng616 (JIRA)" To: issues@spark.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (SPARK-22137) Failed to insert VectorUDT to hive table with DataFrameWriter.insertInto(tableName: String) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 29 Sep 2017 09:04:06 -0000 [ https://issues.apache.org/jira/browse/SPARK-22137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16185535#comment-16185535 ] yzheng616 commented on SPARK-22137: ----------------------------------- Have you tried to use DataFrameWriter.insertInto(tableName: String) API to insert data to the table? > Failed to insert VectorUDT to hive table with DataFrameWriter.insertInto(tableName: String) > ------------------------------------------------------------------------------------------- > > Key: SPARK-22137 > URL: https://issues.apache.org/jira/browse/SPARK-22137 > Project: Spark > Issue Type: Bug > Components: SQL > Affects Versions: 2.1.1 > Reporter: yzheng616 > > Failed to insert VectorUDT to hive table with DataFrameWriter.insertInto(tableName: String). The issue seems similar with SPARK-17765 which have been resolved in 2.1.0. > Error message: > {color:red}Exception in thread "main" org.apache.spark.sql.AnalysisException: cannot resolve '`features`' due to data type mismatch: cannot cast org.apache.spark.ml.linalg.VectorUDT@3bfc3ba7 to StructType(StructField(type,ByteType,true), StructField(size,IntegerType,true), StructField(indices,ArrayType(IntegerType,true),true), StructField(values,ArrayType(DoubleType,true),true));; > 'InsertIntoTable Relation[id#21,features#22] parquet, OverwriteOptions(false,Map()), false > +- 'Project [cast(id#13L as int) AS id#27, cast(features#14 as struct,values:array>) AS features#28] > +- LogicalRDD [id#13L, features#14]{color} > Reproduce code: > {code:java} > import scala.annotation.varargs > import org.apache.spark.ml.linalg.SQLDataTypes > import org.apache.spark.sql.Row > import org.apache.spark.sql.SparkSession > import org.apache.spark.sql.types.LongType > import org.apache.spark.sql.types.StructField > import org.apache.spark.sql.types.StructType > case class UDT(`id`: Long, `features`: org.apache.spark.ml.linalg.Vector) > object UDTTest { > def main(args: Array[String]): Unit = { > val tb = "table_udt" > val spark = SparkSession.builder().master("local[4]").appName("UDTInsertInto").enableHiveSupport().getOrCreate() > spark.sql("drop table if exists " + tb) > > /* > * VectorUDT sql type definition: > * > * override def sqlType: StructType = { > * StructType(Seq( > * StructField("type", ByteType, nullable = false), > * StructField("size", IntegerType, nullable = true), > * StructField("indices", ArrayType(IntegerType, containsNull = false), nullable = true), > * StructField("values", ArrayType(DoubleType, containsNull = false), nullable = true))) > * } > */ > > //Create Hive table base on VectorUDT sql type > spark.sql("create table if not exists "+tb+"(id int, features struct,values:array>)" + > " row format serde 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'"+ > " stored as"+ > " inputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'"+ > " outputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'") > var seq = new scala.collection.mutable.ArrayBuffer[UDT]() > for (x <- 1 to 2) { > seq += (new UDT(x, org.apache.spark.ml.linalg.Vectors.dense(0.2, 0.21, 0.44))) > } > val rowRDD = (spark.sparkContext.makeRDD[UDT](seq)).map { x => Row.fromSeq(Seq(x.id,x.features)) } > val schema = StructType(Array(StructField("id", LongType,false),StructField("features", SQLDataTypes.VectorType,false))) > val df = spark.createDataFrame(rowRDD, schema) > > //insert into hive table > df.write.insertInto(tb) > } > } > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org For additional commands, e-mail: issues-help@spark.apache.org