Skip to content
Snippets Groups Projects
Unverified Commit 90064082 authored by metamben's avatar metamben Committed by GitHub
Browse files

Add joinedThing and pickerInfo (#31933)

* Add joinedThing and pickerInfo

Fixes #31920.
parent 7aa32fdc
Branches
Tags
No related merge requests found
......@@ -115,3 +115,18 @@ export function removeJoin(
): Query {
return ML.remove_join(query, stageIndex, joinSpec);
}
export function joinedThing(query: Query, join: Join): Joinable {
return ML.joined_thing(query, join);
}
export type PickerInfo = {
databaseId: number;
tableId: number;
cardId?: number;
isModel?: boolean;
};
export function pickerInfo(query: Query, metadata: Joinable): PickerInfo {
return ML.picker_info(query, metadata);
}
......@@ -579,3 +579,12 @@
(when-let [pk-col (pk-column query stage-number joinable)]
(when-let [fk-col (fk-column-for query stage-number pk-col)]
(lib.filter/filter-clause (equals-join-condition-operator-definition) fk-col pk-col)))))
(mu/defn joined-thing :- [:maybe [:or lib.metadata/TableMetadata lib.metadata/CardMetadata]]
"Return metadata about the origin of `a-join` using `metadata-providerable` as the source of information."
[metadata-providerable :- lib.metadata/MetadataProviderable
a-join :- ::lib.schema.join/join]
(let [origin (-> a-join :stages first)]
(cond
(:source-card origin) (lib.metadata/card metadata-providerable (:source-card origin))
(:source-table origin) (lib.metadata/table metadata-providerable (:source-table origin)))))
......@@ -11,6 +11,7 @@
[medley.core :as m]
[metabase.lib.convert :as convert]
[metabase.lib.core :as lib.core]
[metabase.lib.join :as lib.join]
[metabase.lib.js.metadata :as js.metadata]
[metabase.lib.metadata.protocols :as lib.metadata.protocols]
[metabase.lib.stage :as lib.stage]
......@@ -520,6 +521,25 @@
[a-query stage-number join-spec]
(lib.core/remove-join a-query stage-number join-spec))
(defn ^:export joined-thing
"Return metadata about the origin of `join` using `metadata-providerable` as the source of information."
[a-query a-join]
(lib.join/joined-thing a-query a-join))
(defn ^:export picker-info
"Temporary solution providing access to internal IDs for the FE to pass on to MLv1 functions."
[a-query metadata]
(case (:lib/type metadata)
:metadata/table #js {:databaseId (:database a-query)
:tableId (:id metadata)}
:metadata/card #js {:databaseId (:database a-query)
:tableId (str "card__" (:id metadata))
:cardId (:id metadata)
:isModel (:dataset metadata)}
(do
(log/warn "Cannot provide picker-info for" (:lib/type metadata))
nil)))
(defn ^:export external-op
"Convert the internal operator `clause` to the external format."
[clause]
......
......@@ -253,6 +253,7 @@
:fields (parse-fields v)
:visibility-type (keyword v)
:dataset-query (js->clj v :keywordize-keys true)
:dataset v
;; this is not complete, add more stuff as needed.
v)))
......@@ -263,7 +264,7 @@
(or (object-get obj "_card")
obj))
(defn- assamble-card
(defn- assemble-card
[metadata id]
(let [parse-card-ignoring-plain-object (parse-object-fn :card {:use-plain-object? false})
parse-card (parse-object-fn :card)]
......@@ -288,7 +289,7 @@
[_object-type metadata]
(into {}
(map (fn [id]
[id (delay (assamble-card metadata id))]))
[id (delay (assemble-card metadata id))]))
(-> #{}
(into (keep lib.util/legacy-string-table-id->card-id)
(gobject/getKeys (object-get metadata "tables")))
......
......@@ -115,7 +115,8 @@
[:dataset-query {:optional true} :map]
;; vector of column metadata maps; these are ALMOST the correct shape to be [[ColumnMetadata]], but they're
;; probably missing `:lib/type` and probably using `:snake_case` keys.
[:result-metadata {:optional true} [:maybe [:sequential :map]]]])
[:result-metadata {:optional true} [:maybe [:sequential :map]]]
[:dataset {:optional true} :boolean]])
(def SegmentMetadata
"More or less the same as a [[metabase.models.segment]], but with kebab-case keys."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment