Skip to content

Commit

Permalink
Merge branch 'main' into b379743612-ml-logistic-regression-explain-pr…
Browse files Browse the repository at this point in the history
…edict
  • Loading branch information
arwas11 authored Dec 17, 2024
2 parents 0f88005 + e0a8288 commit 2812053
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
" </td>\n",
" <td>\n",
" <a href=\"https://pantheon.corp.google.com/bigquery?project=bigframes-dev&ws=!1m7!1m6!12m5!1m3!1sbigframes-dev!2sus-central1!3se8c41ea1-e159-4865-b2b8-5b784176193f!2e2\">\n",
" <img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW1gvOovVlbZAIZylUtf5Iu8-693qS1w5NJw&s\" alt=\"BQ logo\" width=\"35\">\n",
" Open in BQ Studio\n",
" </a>\n",
" </td>\n",
"</table>"
]
},
Expand Down
8 changes: 7 additions & 1 deletion notebooks/generative_ai/bq_dataframes_llm_kmeans.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
" </td>\n",
" <td>\n",
" <a href=\"https://pantheon.corp.google.com/bigquery?project=bigframes-dev&ws=!1m7!1m6!12m5!1m3!1sbigframes-dev!2sus-central1!3s06318b1a-ab57-46e4-b0a2-a0ad6665b0ee!2e2\">\n",
" <img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW1gvOovVlbZAIZylUtf5Iu8-693qS1w5NJw&s\" alt=\"BQ logo\" width=\"35\">\n",
" Open in BQ Studio\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
" </td>\n",
" <td>\n",
" <a href=\"https://pantheon.corp.google.com/bigquery?project=bigframes-dev&ws=!1m7!1m6!12m5!1m3!1sbigframes-dev!2sus-central1!3s4da57cb0-e53d-4bcb-bbe4-d0ad3982648e!2e2\">\n",
" <img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW1gvOovVlbZAIZylUtf5Iu8-693qS1w5NJw&s\" alt=\"BQ logo\" width=\"35\">\n",
" Open in BQ Studio\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
" </td>\n",
" <td>\n",
" <a href=\"https://pantheon.corp.google.com/bigquery?ws=!1m7!1m6!12m5!1m3!1sbigframes-dev!2sus-central1!3sbf431d8d-e7a6-453f-93e6-7b918f348d7f!2e2\">\n",
" <img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW1gvOovVlbZAIZylUtf5Iu8-693qS1w5NJw&s\" alt=\"BQ logo\" width=\"35\">\n",
" Open in BQ Studio\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
" </td>\n",
" <td>\n",
" <a href=\"https://pantheon.corp.google.com/bigquery?ws=!1m7!1m6!12m5!1m3!1sbigframes-dev!2sus-central1!3s52b80d56-2706-4b9d-a1bf-b2770834292a!2e2&project=bigframes-dev\">\n",
" <img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW1gvOovVlbZAIZylUtf5Iu8-693qS1w5NJw&s\" alt=\"BQ logo\" width=\"35\">\n",
" Open in BQ Studio\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td> \n",
" </td>\n",
" <td>\n",
" <a href=\"https://pantheon.corp.google.com/bigquery?project=bigframes-dev&ws=!1m7!1m6!12m5!1m3!1sbigframes-dev!2sus-central1!3s9556e137-dc3d-47d1-9f21-e8c90b01a047!2e2\">\n",
" <img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW1gvOovVlbZAIZylUtf5Iu8-693qS1w5NJw&s\" alt=\"BQ logo\" width=\"35\">\n",
" Open in BQ Studio\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td> \n",
" </td>\n",
" <td>\n",
" <a href=\"https://pantheon.corp.google.com/bigquery?project=bigframes-dev&ws=!1m7!1m6!12m5!1m3!1sbigframes-dev!2sus-central1!3s0c5e7d12-2769-439f-a34a-cf9cb4eb1336!2e2\">\n",
" <img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW1gvOovVlbZAIZylUtf5Iu8-693qS1w5NJw&s\" alt=\"BQ logo\" width=\"35\">\n",
" Open in BQ Studio\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
Expand Down
53 changes: 25 additions & 28 deletions third_party/bigframes_vendored/tpch/queries/q21.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Contains code from https://github.com/pola-rs/tpch/blob/main/queries/duckdb/q21.py

import typing
# Contains code from https://github.com/pola-rs/tpch/blob/main/queries/polars/q21.py

import bigframes
import bigframes.pandas as bpd
Expand All @@ -24,39 +22,38 @@ def q(project_id: str, dataset_id: str, session: bigframes.Session):
index_col=bigframes.enums.DefaultIndexKind.NULL,
)

nation = nation[nation["N_NAME"] == "SAUDI ARABIA"]
orders = orders[orders["O_ORDERSTATUS"] == "F"]

l1 = lineitem[lineitem["L_RECEIPTDATE"] > lineitem["L_COMMITDATE"]][
["L_ORDERKEY", "L_SUPPKEY"]
]
var1 = "SAUDI ARABIA"

l2 = lineitem.groupby("L_ORDERKEY", as_index=False).agg(
NUNIQUE_COL=bpd.NamedAgg(column="L_SUPPKEY", aggfunc="nunique")
q1 = lineitem.groupby("L_ORDERKEY", as_index=False).agg(
N_SUPP_BY_ORDER=bpd.NamedAgg(column="L_SUPPKEY", aggfunc="size")
)
l2 = l2[l2["NUNIQUE_COL"] > 1][["L_ORDERKEY"]]
q1 = q1[q1["N_SUPP_BY_ORDER"] > 1]

l3 = l1.groupby("L_ORDERKEY", as_index=False).agg(
NUNIQUE_COL=bpd.NamedAgg(column="L_SUPPKEY", aggfunc="nunique")
)
l3 = l3[l3["NUNIQUE_COL"] == 1][["L_ORDERKEY"]]
lineitem_filtered = lineitem[lineitem["L_RECEIPTDATE"] > lineitem["L_COMMITDATE"]]

l1 = l1.merge(l2, on="L_ORDERKEY", how="inner").merge(
l3, on="L_ORDERKEY", how="inner"
q1 = q1.merge(lineitem_filtered, on="L_ORDERKEY")

q_final = q1.groupby("L_ORDERKEY", as_index=False).agg(
N_SUPP_BY_ORDER_FINAL=bpd.NamedAgg(column="L_SUPPKEY", aggfunc="size")
)

merged = supplier.merge(nation, left_on="S_NATIONKEY", right_on="N_NATIONKEY")
merged = merged.merge(l1, left_on="S_SUPPKEY", right_on="L_SUPPKEY")
merged = merged.merge(orders, left_on="L_ORDERKEY", right_on="O_ORDERKEY")
q_final = q_final.merge(q1, on="L_ORDERKEY")
q_final = q_final.merge(supplier, left_on="L_SUPPKEY", right_on="S_SUPPKEY")
q_final = q_final.merge(nation, left_on="S_NATIONKEY", right_on="N_NATIONKEY")
q_final = q_final.merge(orders, left_on="L_ORDERKEY", right_on="O_ORDERKEY")

q_final = q_final[
(q_final["N_SUPP_BY_ORDER_FINAL"] == 1)
& (q_final["N_NAME"] == var1)
& (q_final["O_ORDERSTATUS"] == "F")
]

result = merged.groupby("S_NAME", as_index=False).agg(
q_final = q_final.groupby("S_NAME", as_index=False).agg(
NUMWAIT=bpd.NamedAgg(column="L_SUPPKEY", aggfunc="size")
)

result = (
typing.cast(bpd.DataFrame, result)
.sort_values(["NUMWAIT", "S_NAME"], ascending=[False, True])
.head(100)
)
q_final = q_final.sort_values(
by=["NUMWAIT", "S_NAME"], ascending=[False, True]
).head(100)

result.to_gbq()
q_final.to_gbq()

0 comments on commit 2812053

Please sign in to comment.