|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.spark.sql.catalyst.expressions |
| 19 | + |
| 20 | +import org.apache.spark.SparkFunSuite |
| 21 | + |
| 22 | +class NetflixClExpressionsSuit extends SparkFunSuite with ExpressionEvalHelper { |
| 23 | + |
| 24 | + private val snapshot = |
| 25 | + """ |
| 26 | + |[{"sequence":1,"id":757294327146741,"source":"iOS","schema":{"name":"App","version":"1.26.0"},"type":["Log","Session"],"time":559440041005}, |
| 27 | + |{"type":["ProcessState"],"id":757294397275504,"computation":"none","allocation":"none","interaction":"none"}, |
| 28 | + |{"type":["ProcessState"],"id":757294425125683,"computation":"normal","allocation":"normal","interaction":"direct"}, |
| 29 | + |{"sequence":3,"id":757294439218544,"type":["ProcessStateTransition","Action","Session"],"time":559440041006}, |
| 30 | + |{"nfvdid":"blahblablb","id":757294485523660,"sequence":4,"type":["VisitorDeviceId","AccountIdentity","Session"],"time":559440041008}, |
| 31 | + |{"sequence":5,"id":757294513373839,"type":["UserInteraction","Session"],"time":559440041008}, |
| 32 | + |{"model":"APPLE_iPhone9-1","type":["Device"],"id":757294562698854}, |
| 33 | + |{"type":["OsVersion"],"osVersion":"11.4.1","id":757294575785082}, |
| 34 | + |{"appVersion":"11.2.0","type":["AppVersion"],"id":757294615379312}, |
| 35 | + |{"uiVersion":"ios11.2.0 (2265)","type":["UiVersion"],"id":757294643565035}, |
| 36 | + |{"esn":"","type":["Esn"],"id":757294732484280}, |
| 37 | + |{"type":["NrdLib"],"id":757294743557242,"appVersion":"11.2.0 (2265)","sdkVersion":"2012.4","libVersion":"2012.4"}, |
| 38 | + |{"userAgent":" App/11.2.0 ( iOS 11.4.1 )","type":["UserAgent"],"id":757294786171371}, |
| 39 | + |{"utcOffset":-18000,"type":["TimeZone"],"id":757294829121044}, |
| 40 | + |{"muting":false,"id":757294867037552,"level":0.875,"type":["Volume"]}, |
| 41 | + |{"type":["WifiConnection","NetworkConnection"],"id":757294904954060}, |
| 42 | + |{"type":["UiLocale"],"uiLocale":"en","id":757294954950164}, |
| 43 | + |{"cells":{"7972":1,"10953":4},"type":["TestAllocations"],"id":757294995551027}, |
| 44 | + |{"trackingInfo":{"videoId":12345,"trackId":9087,"imageKey":"test1"},"sequence":9,"id":757295011213817,"view":"browseTitles","type":["Presentation","Session"],"time":559440043683}, |
| 45 | + |{"trackingInfo":{"surveyResponse":1,"surveyIdentifier":"IO_80203147"},"sequence":11,"id":757295111313817,"view":"homeTab","type":["Focus","Session"],"time":559440043683}] |
| 46 | + """.stripMargin.replace("\n", "") |
| 47 | + |
| 48 | + test("function with only `clType`") { |
| 49 | + val result = List( |
| 50 | + "{\"id\":757295111313817,\"sequence\":11,\"time\":559440043683,\"trackingInfo\":{\"surveyIdentifier\":\"IO_80203147\",\"surveyResponse\":1},\"type\":[\"Focus\",\"Session\"],\"view\":\"homeTab\"}" |
| 51 | + ) |
| 52 | + checkEvaluation(ClSnapshotExtract(Literal(snapshot), |
| 53 | + Literal("Focus"), |
| 54 | + Literal(""), |
| 55 | + Literal("")), |
| 56 | + result) |
| 57 | + val result1 = List( |
| 58 | + "{\"id\":757294327146741,\"schema\":{\"name\":\"App\",\"version\":\"1.26.0\"},\"sequence\":1,\"source\":\"iOS\",\"time\":559440041005,\"type\":[\"Log\",\"Session\"]}", |
| 59 | + "{\"id\":757294439218544,\"sequence\":3,\"time\":559440041006,\"type\":[\"ProcessStateTransition\",\"Action\",\"Session\"]}", |
| 60 | + "{\"id\":757294485523660,\"nfvdid\":\"blahblablb\",\"sequence\":4,\"time\":559440041008,\"type\":[\"VisitorDeviceId\",\"AccountIdentity\",\"Session\"]}", |
| 61 | + "{\"id\":757294513373839,\"sequence\":5,\"time\":559440041008,\"type\":[\"UserInteraction\",\"Session\"]}", |
| 62 | + "{\"id\":757295011213817,\"sequence\":9,\"time\":559440043683,\"trackingInfo\":{\"imageKey\":\"test1\",\"trackId\":9087,\"videoId\":12345},\"type\":[\"Presentation\",\"Session\"],\"view\":\"browseTitles\"}", |
| 63 | + "{\"id\":757295111313817,\"sequence\":11,\"time\":559440043683,\"trackingInfo\":{\"surveyIdentifier\":\"IO_80203147\",\"surveyResponse\":1},\"type\":[\"Focus\",\"Session\"],\"view\":\"homeTab\"}" |
| 64 | + ) |
| 65 | + checkEvaluation(ClSnapshotExtract(Literal(snapshot), |
| 66 | + Literal("Session"), |
| 67 | + Literal(""), |
| 68 | + Literal("")), |
| 69 | + result1) |
| 70 | + } |
| 71 | + |
| 72 | + test("function with `clType` and `extractCriteria`") { |
| 73 | + val result = List("\"homeTab\"") |
| 74 | + checkEvaluation(ClSnapshotExtract(Literal(snapshot), |
| 75 | + Literal("Focus"), |
| 76 | + Literal("view"), |
| 77 | + Literal("")), |
| 78 | + result) |
| 79 | + val result1 = List("1") |
| 80 | + checkEvaluation(ClSnapshotExtract(Literal(snapshot), |
| 81 | + Literal("Focus"), |
| 82 | + Literal("trackingInfo.surveyResponse"), |
| 83 | + Literal("")), |
| 84 | + result1) |
| 85 | + } |
| 86 | + |
| 87 | + test("function with all the arguments present") { |
| 88 | + val result = |
| 89 | + List("{\"surveyIdentifier\":\"IO_80203147\",\"surveyResponse\":1}") |
| 90 | + checkEvaluation(ClSnapshotExtract(Literal(snapshot), |
| 91 | + Literal("Focus"), |
| 92 | + Literal("trackingInfo"), |
| 93 | + Literal("view==\"homeTab\"")), |
| 94 | + result) |
| 95 | + val result1 = List("\"IO_80203147\"") |
| 96 | + checkEvaluation( |
| 97 | + ClSnapshotExtract( |
| 98 | + Literal(snapshot), |
| 99 | + Literal("Focus"), |
| 100 | + Literal("trackingInfo.surveyIdentifier"), |
| 101 | + Literal("view==\"homeTab\" && trackingInfo.surveyResponse==1")), |
| 102 | + result1 |
| 103 | + ) |
| 104 | + val result3 = List() |
| 105 | + checkEvaluation( |
| 106 | + ClSnapshotExtract( |
| 107 | + Literal(snapshot), |
| 108 | + Literal("Focus"), |
| 109 | + Literal("trackingInfo.surveyIdentifier"), |
| 110 | + Literal("view==\"browseTitles\" && trackingInfo.surveyResponse==1")), |
| 111 | + result3 |
| 112 | + ) |
| 113 | + val result4 = List("\"test1\"") |
| 114 | + checkEvaluation( |
| 115 | + ClSnapshotExtract( |
| 116 | + Literal(snapshot), |
| 117 | + Literal("Presentation"), |
| 118 | + Literal("trackingInfo.imageKey"), |
| 119 | + Literal( |
| 120 | + "view==\"browseTitles\" && ( trackingInfo.trackId==9087 || trackingInfo.videoId == 12345 )") |
| 121 | + ), |
| 122 | + result4 |
| 123 | + ) |
| 124 | + } |
| 125 | + |
| 126 | + test("function without `clType` parameter") { |
| 127 | + try { |
| 128 | + ClSnapshotExtract( |
| 129 | + Literal(snapshot), |
| 130 | + Literal(null), |
| 131 | + Literal("trackingInfo.imageKey"), |
| 132 | + Literal( |
| 133 | + "view==\"browseTitles\" && ( trackingInfo.trackId==9087 || trackingInfo.videoId == 12345 )") |
| 134 | + ) |
| 135 | + } catch { |
| 136 | + case _: IllegalArgumentException => |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | +} |
0 commit comments