1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ package org .apache .carbondata .spark .testsuite .insertQuery
20
+
21
+ import org .apache .spark .sql .Row
22
+ import org .apache .spark .sql .test .util .QueryTest
23
+ import org .scalatest .BeforeAndAfterAll
24
+
25
+
26
+ class InsertIntoNonCarbonTableTestCase extends QueryTest with BeforeAndAfterAll {
27
+ override def beforeAll {
28
+ sql(" drop table if exists TCarbonSource" )
29
+ sql(
30
+ " create table TCarbonSource (imei string,deviceInformationId int,MAC string,deviceColor " +
31
+ " string,device_backColor string,modelId string,marketName string,AMSize string,ROMSize " +
32
+ " string,CUPAudit string,CPIClocked string,series string,productionDate timestamp,bomCode " +
33
+ " string,internalModels string, deliveryTime string, channelsId string, channelsName string " +
34
+ " , deliveryAreaId string, deliveryCountry string, deliveryProvince string, deliveryCity " +
35
+ " string,deliveryDistrict string, deliveryStreet string, oxSingleNumber string, " +
36
+ " ActiveCheckTime string, ActiveAreaId string, ActiveCountry string, ActiveProvince string, " +
37
+ " Activecity string, ActiveDistrict string, ActiveStreet string, ActiveOperatorId string, " +
38
+ " Active_releaseId string, Active_EMUIVersion string, Active_operaSysVersion string, " +
39
+ " Active_BacVerNumber string, Active_BacFlashVer string, Active_webUIVersion string, " +
40
+ " Active_webUITypeCarrVer string,Active_webTypeDataVerNumber string, Active_operatorsVersion" +
41
+ " string, Active_phonePADPartitionedVersions string, Latest_YEAR int, Latest_MONTH int, " +
42
+ " Latest_DAY Decimal(30,10), Latest_HOUR string, Latest_areaId string, Latest_country " +
43
+ " string, Latest_province string, Latest_city string, Latest_district string, Latest_street " +
44
+ " string, Latest_releaseId string, Latest_EMUIVersion string, Latest_operaSysVersion string," +
45
+ " Latest_BacVerNumber string, Latest_BacFlashVer string, Latest_webUIVersion string, " +
46
+ " Latest_webUITypeCarrVer string, Latest_webTypeDataVerNumber string, " +
47
+ " Latest_operatorsVersion string, Latest_phonePADPartitionedVersions string, " +
48
+ " Latest_operatorId string, gamePointDescription string,gamePointId double,contractNumber " +
49
+ " BigInt) STORED BY 'org.apache.carbondata.format'" )
50
+ sql(
51
+ s " LOAD DATA INPATH ' $resourcesPath/100_olap.csv' INTO table TCarbonSource options " +
52
+ " ('DELIMITER'=',', 'QUOTECHAR'='\' , 'FILEHEADER'='imei,deviceInformationId,MAC,deviceColor," +
53
+ " device_backColor,modelId,marketName,AMSize,ROMSize,CUPAudit,CPIClocked,series," +
54
+ " productionDate,bomCode,internalModels,deliveryTime,channelsId,channelsName,deliveryAreaId," +
55
+ " deliveryCountry,deliveryProvince,deliveryCity,deliveryDistrict,deliveryStreet," +
56
+ " oxSingleNumber,ActiveCheckTime,ActiveAreaId,ActiveCountry,ActiveProvince,Activecity," +
57
+ " ActiveDistrict,ActiveStreet,ActiveOperatorId,Active_releaseId,Active_EMUIVersion," +
58
+ " Active_operaSysVersion,Active_BacVerNumber,Active_BacFlashVer,Active_webUIVersion," +
59
+ " Active_webUITypeCarrVer,Active_webTypeDataVerNumber,Active_operatorsVersion," +
60
+ " Active_phonePADPartitionedVersions,Latest_YEAR,Latest_MONTH,Latest_DAY,Latest_HOUR," +
61
+ " Latest_areaId,Latest_country,Latest_province,Latest_city,Latest_district,Latest_street," +
62
+ " Latest_releaseId,Latest_EMUIVersion,Latest_operaSysVersion,Latest_BacVerNumber," +
63
+ " Latest_BacFlashVer,Latest_webUIVersion,Latest_webUITypeCarrVer," +
64
+ " Latest_webTypeDataVerNumber,Latest_operatorsVersion,Latest_phonePADPartitionedVersions," +
65
+ " Latest_operatorId,gamePointDescription,gamePointId,contractNumber', " +
66
+ " 'bad_records_logger_enable'='false','bad_records_action'='FORCE')" )
67
+ }
68
+
69
+ test(" insert into hive" ) {
70
+ sql(" drop table if exists thive2" )
71
+ sql(
72
+ " create table thive2 row format delimited fields terminated by '\017 ' stored as textfile as" +
73
+ " select imei,deviceInformationId,MAC from TCarbonSource" )
74
+ checkAnswer(
75
+ sql(
76
+ " select imei,deviceInformationId,MAC from TCarbonSource order by imei, " +
77
+ " deviceInformationId,MAC" ),
78
+ sql(" select imei,deviceInformationId,MAC from thive2 order by imei,deviceInformationId,MAC" )
79
+ )
80
+ sql(" drop table thive2" )
81
+ }
82
+ test(" insert into parquet" ) {
83
+ sql(" drop table if exists tparquet" )
84
+ sql(" create table tparquet(imei string,deviceInformationId int) STORED AS PARQUET" )
85
+ sql(" insert into tparquet select imei,deviceInformationId from TCarbonSource" )
86
+ checkAnswer(
87
+ sql(" select imei,deviceInformationId from TCarbonSource order by imei,deviceInformationId" ),
88
+ sql(" select imei,deviceInformationId from tparquet order by imei,deviceInformationId" )
89
+ )
90
+ sql(" drop table tparquet" )
91
+ }
92
+ test(" insert into hive conditional" ) {
93
+ sql(" drop table if exists thive_cond" )
94
+ sql(
95
+ " create table thive_cond row format delimited fields terminated by '\017 ' stored as " +
96
+ " textfile as SELECT(CASE WHEN imei IS NOT NULL THEN imei ELSE MAC END) AS temp FROM " +
97
+ " TCarbonSource limit 10" )
98
+ checkAnswer(
99
+ sql(" select count(*) from thive_cond" ),
100
+ Seq (Row (10 ))
101
+ )
102
+ sql(" drop table thive_cond" )
103
+ }
104
+
105
+ override def afterAll {
106
+ sql(" DROP TABLE IF EXISTS TCarbonSource" )
107
+ }
108
+ }
0 commit comments