1717package org .apache .spark .aliyun .odps .datasource
1818
1919import java .io .EOFException
20- import java .sql .{Date , SQLException }
2120import scala .collection .JavaConverters ._
2221import scala .collection .mutable .ArrayBuffer
2322import com .aliyun .odps .{Odps , PartitionSpec }
2423import com .aliyun .odps .account .AliyunAccount
2524import com .aliyun .odps .tunnel .TableTunnel
26- import com .aliyun .odps .tunnel .io .TunnelRecordReader
2725import org .apache .spark .{InterruptibleIterator , Partition , SparkContext , TaskContext }
2826import org .apache .spark .aliyun .odps .OdpsPartition
2927import org .apache .spark .aliyun .utils .OdpsUtils
3028import org .apache .spark .rdd .RDD
3129import org .apache .spark .sql .catalyst .InternalRow
3230import org .apache .spark .sql .catalyst .expressions .SpecificInternalRow
33- import org .apache .spark .sql .catalyst .util .DateTimeUtils
3431import org .apache .spark .sql .types ._
35- import org .apache .spark .unsafe .types .UTF8String
3632import org .apache .spark .util .NextIterator
3733
3834class ODPSRDD (
@@ -84,124 +80,8 @@ class ODPSRDD(
8480 schema.zipWithIndex.foreach {
8581 case (s : StructField , idx : Int ) =>
8682 try {
87- s.dataType match {
88- case LongType =>
89- val value = r.getBigint(s.name)
90- if (value != null ) {
91- mutableRow.setLong(idx, value)
92- } else {
93- mutableRow.update(idx, null )
94- }
95- case BooleanType =>
96- val value = r.getBoolean(s.name)
97- if (value != null ) {
98- mutableRow.setBoolean(idx, value)
99- } else {
100- mutableRow.update(idx, null )
101- }
102- case DoubleType =>
103- val value = r.getDouble(s.name)
104- if (value != null ) {
105- mutableRow.setDouble(idx, value)
106- } else {
107- mutableRow.update(idx, null )
108- }
109- case ShortType =>
110- val value = r.get(s.name)
111- if (value != null ) {
112- mutableRow.setShort(idx, value.asInstanceOf [Short ])
113- } else {
114- mutableRow.update(idx, null )
115- }
116- case ByteType =>
117- val value = r.get(s.name)
118- if (value != null ) {
119- mutableRow.setByte(idx, value.asInstanceOf [Byte ])
120- } else {
121- mutableRow.update(idx, null )
122- }
123- case DateType =>
124- val value = r.get(s.name)
125- value match {
126- case date1 : java.sql.Date =>
127- mutableRow.update(idx, DateTimeUtils .fromJavaDate(date1))
128- case date2 : java.util.Date =>
129- mutableRow.setInt(idx,
130- DateTimeUtils .fromJavaDate(new Date (date2.getTime)))
131- case null => mutableRow.update(idx, null )
132- case _ => throw new SQLException (s " Unknown type " +
133- s " ${value.getClass.getCanonicalName}" )
134- }
135- case TimestampType =>
136- val value = r.get(s.name)
137- value match {
138- case timestamp : java.sql.Timestamp =>
139- mutableRow.setLong(idx, DateTimeUtils .fromJavaTimestamp(timestamp))
140- case null => mutableRow.update(idx, null )
141- case _ => throw new SQLException (s " Unknown type " +
142- s " ${value.getClass.getCanonicalName}" )
143- }
144- case DecimalType .SYSTEM_DEFAULT =>
145- val value = r.get(s.name)
146- if (value != null ) {
147- mutableRow.update(idx,
148- new Decimal ().set(value.asInstanceOf [java.math.BigDecimal ]))
149- } else {
150- mutableRow.update(idx, null )
151- }
152- case FloatType =>
153- val value = r.get(s.name)
154- if (value != null ) {
155- mutableRow.update(idx, value.asInstanceOf [Float ])
156- } else {
157- mutableRow.update(idx, null )
158- }
159- case IntegerType =>
160- val value = r.get(s.name)
161- value match {
162- case e : java.lang.Integer =>
163- mutableRow.update(idx, e.toInt)
164- case null => mutableRow.update(idx, null )
165- case _ => throw new SQLException (s " Unknown type " +
166- s " ${value.getClass.getCanonicalName}" )
167- }
168- case StringType =>
169- val value = r.get(s.name)
170- value match {
171- case e : com.aliyun.odps.data.Char =>
172- mutableRow.update(idx, UTF8String .fromString(e.toString))
173- case e : com.aliyun.odps.data.Varchar =>
174- mutableRow.update(idx, UTF8String .fromString(e.toString))
175- case e : String =>
176- mutableRow.update(idx, UTF8String .fromString(e))
177- case e : Array [Byte ] =>
178- mutableRow.update(idx, UTF8String .fromBytes(e))
179- case null => mutableRow.update(idx, null )
180- case _ => throw new SQLException (s " Unknown type " +
181- s " ${value.getClass.getCanonicalName}" )
182- }
183- case BinaryType =>
184- val value = r.get(s.name)
185- value match {
186- case e : com.aliyun.odps.data.Binary =>
187- mutableRow.update(idx, e.data())
188- case null => mutableRow.update(idx, null )
189- case _ => throw new SQLException (s " Unknown type " +
190- s " ${value.getClass.getCanonicalName}" )
191- }
192- case ArrayType (_, _) =>
193- val value = r.get(s.name)
194- mutableRow.update(idx, OdpsUtils .odpsData2SparkData(typeInfos(idx))(value))
195- case MapType (_, _, _) =>
196- val value = r.get(s.name)
197- mutableRow.update(idx, OdpsUtils .odpsData2SparkData(typeInfos(idx))(value))
198- case StructType (_) =>
199- val value = r.get(s.name)
200- mutableRow.update(idx, OdpsUtils .odpsData2SparkData(typeInfos(idx))(value))
201- case NullType =>
202- mutableRow.setNullAt(idx)
203- case _ => throw new SQLException (s " Unknown type " )
204- }
83+ val value = r.get(s.name)
84+ mutableRow.update(idx, OdpsUtils .odpsData2SparkData(typeInfos(idx))(value))
20585 } catch {
20686 case e : Exception =>
20787 log.error(s " Can not transfer record column value, idx: $idx, " +
@@ -224,7 +104,7 @@ class ODPSRDD(
224104
225105 override def close () {
226106 try {
227- val totalBytes = reader.asInstanceOf [ TunnelRecordReader ]. getTotalBytes
107+ val totalBytes = reader.getTotalBytes
228108 inputMetrics.incBytesRead(totalBytes)
229109 reader.close()
230110 } catch {
0 commit comments