|
4 | 4 | "cell_type": "markdown",
|
5 | 5 | "metadata": {
|
6 | 6 | "application/vnd.databricks.v1+cell": {
|
7 |
| - "cellMetadata": {}, |
| 7 | + "cellMetadata": { |
| 8 | + "byteLimit": 2048000, |
| 9 | + "rowLimit": 10000 |
| 10 | + }, |
8 | 11 | "inputWidgets": {},
|
9 | 12 | "nuid": "44cd2565-3e27-417c-8c6c-7b2d8f1b94c5",
|
10 | 13 | "showTitle": false,
|
|
21 | 24 | "execution_count": 0,
|
22 | 25 | "metadata": {
|
23 | 26 | "application/vnd.databricks.v1+cell": {
|
24 |
| - "cellMetadata": {}, |
| 27 | + "cellMetadata": { |
| 28 | + "byteLimit": 2048000, |
| 29 | + "rowLimit": 10000 |
| 30 | + }, |
25 | 31 | "inputWidgets": {},
|
26 | 32 | "nuid": "e6da106f-4e0b-41e0-9f75-6e329535d5c0",
|
27 | 33 | "showTitle": false,
|
|
40 | 46 | "cell_type": "markdown",
|
41 | 47 | "metadata": {
|
42 | 48 | "application/vnd.databricks.v1+cell": {
|
43 |
| - "cellMetadata": {}, |
| 49 | + "cellMetadata": { |
| 50 | + "byteLimit": 2048000, |
| 51 | + "rowLimit": 10000 |
| 52 | + }, |
44 | 53 | "inputWidgets": {},
|
45 | 54 | "nuid": "f0267197-68d5-4180-8492-6999c905acb1",
|
46 | 55 | "showTitle": false,
|
|
135 | 144 | "execution_count": 0,
|
136 | 145 | "metadata": {
|
137 | 146 | "application/vnd.databricks.v1+cell": {
|
138 |
| - "cellMetadata": {}, |
| 147 | + "cellMetadata": { |
| 148 | + "byteLimit": 2048000, |
| 149 | + "rowLimit": 10000 |
| 150 | + }, |
139 | 151 | "inputWidgets": {},
|
140 | 152 | "nuid": "e98c62a4-8cd4-48d6-9337-86cf54c19ddd",
|
141 | 153 | "showTitle": false,
|
142 | 154 | "tableResultSettingsMap": {},
|
143 | 155 | "title": ""
|
144 | 156 | }
|
145 | 157 | },
|
146 |
| - "outputs": [], |
| 158 | + "outputs": [ |
| 159 | + { |
| 160 | + "output_type": "stream", |
| 161 | + "name": "stdout", |
| 162 | + "output_type": "stream", |
| 163 | + "text": [ |
| 164 | + "+-----------+---------+\n|customer_id| name|\n+-----------+---------+\n| 1| Winston|\n| 2| Jonathan|\n| 3|Annabelle|\n| 4| Marwan|\n| 5| Khaled|\n+-----------+---------+\n\n+--------+----------+-----------+----+\n|order_id|order_date|customer_id|cost|\n+--------+----------+-----------+----+\n| 1|2020-07-31| 1| 30|\n| 2|2020-07-30| 2| 40|\n| 3|2020-07-31| 3| 70|\n| 4|2020-07-29| 4| 100|\n| 5|2020-06-10| 1|1010|\n| 6|2020-08-01| 2| 102|\n| 7|2020-08-01| 3| 111|\n| 8|2020-08-03| 1| 99|\n| 9|2020-08-07| 2| 32|\n| 10|2020-07-15| 1| 2|\n+--------+----------+-----------+----+\n\n" |
| 165 | + ] |
| 166 | + } |
| 167 | + ], |
147 | 168 | "source": [
|
148 | 169 | "customers_data_1532 = [\n",
|
149 | 170 | " (1, \"Winston\"),\n",
|
|
173 | 194 | "orders_df_1532 = spark.createDataFrame(orders_data_1532, orders_columns_1532)\n",
|
174 | 195 | "orders_df_1532.show()"
|
175 | 196 | ]
|
| 197 | + }, |
| 198 | + { |
| 199 | + "cell_type": "code", |
| 200 | + "execution_count": 0, |
| 201 | + "metadata": { |
| 202 | + "application/vnd.databricks.v1+cell": { |
| 203 | + "cellMetadata": { |
| 204 | + "byteLimit": 2048000, |
| 205 | + "rowLimit": 10000 |
| 206 | + }, |
| 207 | + "inputWidgets": {}, |
| 208 | + "nuid": "6d88aa97-0574-4357-a6dd-60243fd246a9", |
| 209 | + "showTitle": false, |
| 210 | + "tableResultSettingsMap": {}, |
| 211 | + "title": "" |
| 212 | + } |
| 213 | + }, |
| 214 | + "outputs": [], |
| 215 | + "source": [ |
| 216 | + "orders_df_1532 = orders_df_1532\\\n", |
| 217 | + " .withColumn(\"order_date\", to_date(\"order_date\"))" |
| 218 | + ] |
| 219 | + }, |
| 220 | + { |
| 221 | + "cell_type": "code", |
| 222 | + "execution_count": 0, |
| 223 | + "metadata": { |
| 224 | + "application/vnd.databricks.v1+cell": { |
| 225 | + "cellMetadata": { |
| 226 | + "byteLimit": 2048000, |
| 227 | + "rowLimit": 10000 |
| 228 | + }, |
| 229 | + "inputWidgets": {}, |
| 230 | + "nuid": "e0086902-35f1-437b-954c-c8805537020e", |
| 231 | + "showTitle": false, |
| 232 | + "tableResultSettingsMap": {}, |
| 233 | + "title": "" |
| 234 | + } |
| 235 | + }, |
| 236 | + "outputs": [], |
| 237 | + "source": [ |
| 238 | + "df_1532 = customers_df_1532\\\n", |
| 239 | + " .join(orders_df_1532, on=\"customer_id\", how=\"inner\")" |
| 240 | + ] |
| 241 | + }, |
| 242 | + { |
| 243 | + "cell_type": "code", |
| 244 | + "execution_count": 0, |
| 245 | + "metadata": { |
| 246 | + "application/vnd.databricks.v1+cell": { |
| 247 | + "cellMetadata": { |
| 248 | + "byteLimit": 2048000, |
| 249 | + "rowLimit": 10000 |
| 250 | + }, |
| 251 | + "inputWidgets": {}, |
| 252 | + "nuid": "ab9e9b75-e19d-456c-8bf8-32308152dcbe", |
| 253 | + "showTitle": false, |
| 254 | + "tableResultSettingsMap": {}, |
| 255 | + "title": "" |
| 256 | + } |
| 257 | + }, |
| 258 | + "outputs": [], |
| 259 | + "source": [ |
| 260 | + "window_spec = Window.partitionBy(\"customer_id\").orderBy(col(\"order_date\").desc())" |
| 261 | + ] |
| 262 | + }, |
| 263 | + { |
| 264 | + "cell_type": "code", |
| 265 | + "execution_count": 0, |
| 266 | + "metadata": { |
| 267 | + "application/vnd.databricks.v1+cell": { |
| 268 | + "cellMetadata": { |
| 269 | + "byteLimit": 2048000, |
| 270 | + "rowLimit": 10000 |
| 271 | + }, |
| 272 | + "inputWidgets": {}, |
| 273 | + "nuid": "169bb6d6-a4a1-4a95-8ebd-bb52719e9243", |
| 274 | + "showTitle": false, |
| 275 | + "tableResultSettingsMap": {}, |
| 276 | + "title": "" |
| 277 | + } |
| 278 | + }, |
| 279 | + "outputs": [], |
| 280 | + "source": [ |
| 281 | + "df_ranked_1532 = df_1532\\\n", |
| 282 | + " .withColumn(\"rank\", row_number().over(window_spec)) \\\n", |
| 283 | + " .filter(col(\"rank\") <= 3)" |
| 284 | + ] |
| 285 | + }, |
| 286 | + { |
| 287 | + "cell_type": "code", |
| 288 | + "execution_count": 0, |
| 289 | + "metadata": { |
| 290 | + "application/vnd.databricks.v1+cell": { |
| 291 | + "cellMetadata": { |
| 292 | + "byteLimit": 2048000, |
| 293 | + "rowLimit": 10000 |
| 294 | + }, |
| 295 | + "inputWidgets": {}, |
| 296 | + "nuid": "241762cc-944b-414f-b2b1-83cea03eca71", |
| 297 | + "showTitle": false, |
| 298 | + "tableResultSettingsMap": {}, |
| 299 | + "title": "" |
| 300 | + } |
| 301 | + }, |
| 302 | + "outputs": [ |
| 303 | + { |
| 304 | + "output_type": "stream", |
| 305 | + "name": "stdout", |
| 306 | + "output_type": "stream", |
| 307 | + "text": [ |
| 308 | + "+-------------+-----------+--------+----------+\n|customer_name|customer_id|order_id|order_date|\n+-------------+-----------+--------+----------+\n| Annabelle| 3| 7|2020-08-01|\n| Annabelle| 3| 3|2020-07-31|\n| Jonathan| 2| 9|2020-08-07|\n| Jonathan| 2| 6|2020-08-01|\n| Jonathan| 2| 2|2020-07-30|\n| Marwan| 4| 4|2020-07-29|\n| Winston| 1| 8|2020-08-03|\n| Winston| 1| 1|2020-07-31|\n| Winston| 1| 10|2020-07-15|\n+-------------+-----------+--------+----------+\n\n" |
| 309 | + ] |
| 310 | + } |
| 311 | + ], |
| 312 | + "source": [ |
| 313 | + "df_ranked_1532\\\n", |
| 314 | + " .select(\n", |
| 315 | + " col(\"name\").alias(\"customer_name\"),\n", |
| 316 | + " \"customer_id\",\n", |
| 317 | + " \"order_id\",\n", |
| 318 | + " \"order_date\"\n", |
| 319 | + " ).orderBy(\n", |
| 320 | + " col(\"customer_name\").asc(),\n", |
| 321 | + " col(\"customer_id\").asc(),\n", |
| 322 | + " col(\"order_date\").desc()\n", |
| 323 | + " ).show()" |
| 324 | + ] |
176 | 325 | }
|
177 | 326 | ],
|
178 | 327 | "metadata": {
|
179 | 328 | "application/vnd.databricks.v1+notebook": {
|
180 |
| - "computePreferences": null, |
| 329 | + "computePreferences": { |
| 330 | + "hardware": { |
| 331 | + "accelerator": null, |
| 332 | + "gpuPoolId": null, |
| 333 | + "memory": null |
| 334 | + } |
| 335 | + }, |
181 | 336 | "dashboards": [],
|
182 | 337 | "environmentMetadata": {
|
183 | 338 | "base_environment": "",
|
184 |
| - "environment_version": "1" |
| 339 | + "environment_version": "2" |
185 | 340 | },
|
186 | 341 | "inputWidgetPreferences": null,
|
187 | 342 | "language": "python",
|
|
0 commit comments