Skip to content

Commit

Permalink
Merge branch 'master' into jh-billing-status
Browse files Browse the repository at this point in the history
  • Loading branch information
qwef committed Feb 9, 2024
2 parents 7b0ff08 + eeda0a8 commit 26e2dfe
Show file tree
Hide file tree
Showing 90 changed files with 2,288 additions and 397 deletions.
21 changes: 14 additions & 7 deletions dev/src/dev.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
[dev.model-tracking :as model-tracking]
[hashp.core :as hashp]
[honey.sql :as sql]
[java-time :as t]
[java-time.api :as t]
[malli.dev :as malli-dev]
[metabase.api.common :as api]
[metabase.config :as config]
Expand Down Expand Up @@ -329,6 +329,10 @@
[form]
(hashp/p* form))

(defn- tests-in-var-ns [test-var]
(->> test-var meta :ns ns-interns vals
(filter (comp :test meta))))

(defn find-root-test-failure!
"Sometimes tests fail due to another test not cleaning up after itself properly (e.g. leaving permissions in a dirty
state). This is a common cause of tests failing in CI, or when run via `find-and-run-tests`, but not when run alone.
Expand All @@ -339,13 +343,16 @@
When the passed test starts failing, it throws an exception notifying you of the test that caused it to start
failing. At that point, you can start investigating what pleasant surprises that test is leaving behind in the
database."
[failing-test-var]
[failing-test-var & {:keys [scope] :or {scope :same-ns}}]
(let [failed? (fn []
(not= [0 0] ((juxt :fail :error) (clojure.test/run-test-var failing-test-var))))]
(when (failed?)
(throw (ex-info "Test is already failing! Better go fix it." {:failed-test failing-test-var})))
(doseq [test (metabase.test-runner/find-tests)]
(clojure.test/run-test-var test)
(when (failed?)
(throw (ex-info (format "Test failed after running: `%s`" test)
{:test test}))))))
(let [tests (case scope
:same-ns (tests-in-var-ns failing-test-var)
:full-suite (metabase.test-runner/find-tests))]
(doseq [test tests]
(clojure.test/run-test-var test)
(when (failed?)
(throw (ex-info (format "Test failed after running: `%s`" test)
{:test test})))))))
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Metabase's reference documentation.
- [Table metadata admin settings](./data-modeling/metadata-editing.md)
- [Field types](./data-modeling/field-types.md)
- [Formatting defaults](./data-modeling/formatting.md)
- [Working with JSON](./data-modeling/json-unfolding.md)
- [Segments and metrics](./data-modeling/segments-and-metrics.md)

### Actions
Expand Down
4 changes: 4 additions & 0 deletions docs/data-modeling/field-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ If you're an administrator, you can edit field types using the [Table Metadata p

While data types themselves can't be edited in Metabase, admins can manually [cast data types](./metadata-editing.md#casting-to-a-specific-data-type) to be read differently, like interpreting a numerical data type as a date format.

### JSON unfolding

See [Working with JSON](./json-unfolding.md).

## Further Reading

- [Exploring data with Metabase's data browser](https://www.metabase.com/learn/getting-started/data-browser.html).
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/data-modeling/images/unfolded-fields.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/data-modeling/images/unfolded-values.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions docs/data-modeling/json-unfolding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Working with JSON
---

# Working with JSON

With [some databases](#databases-that-support-json-unfolding), Metabase can unfold JSON columns into their component fields, which you can then filter on using the query builder.

Here is a table with a column that contains JSON.

![A table with a JSON column](./images/table-with-json-column.png)

Metabase can unfold that JSON column so that each key in the JSON object gets its own column in the table. Here are the unfolded fields of the table with the JSON column pictured above:

![Unfolded fields](./images/unfolded-fields.png)

And here are the values as seen in the table:

![Unfolded values](./images/unfolded-values.png)

This unfolding allows you to filter for values found in the original JSON object.

Metabase will prefix the unfolded column names with the name of the original column that contained the JSON. You can change the column names in **Admin settings** > [Table metadata](metadata-editing.md), or by creating a [model](./models.md) and editing the column metadata.

## Toggling JSON unfolding for a database

If you notice a hit to performance from this JSON unfolding, we recommend turning it off.

To turn off JSON unfolding for a database:

1. Click on the **Gear** in the upper right.
2. Select **Admin settings**
3. Visit the **Databases** tab.
4. Select the relevant database.
5. Click **Show advanced options**.
6. Toggle **Allow unfolding of JSON columns**.
7. Scroll down and click the **Save changes** button.
8. Click **Sync database schema now**.
9. Click **Re-scan field values now**.

## Toggling JSON unfolding for a specific column

If performance degrades, or you'd rather keep the JSON contained in the original column, you can turn off unfolding for individual fields in their settings.

1. Click on the **Gear** in the upper right.
2. Select **Admin settings**.
3. Visit the **Table metadata** tab.
4. Select the database that contains the field you want to update.
5. Select the table that contains the field.
6. Select the field containing the original JSON
7. Scroll to the **Unfold JSON** option and select **Yes** or **No**. If the column was unfolded, Metabase will have hidden this JSON columnn from view, so if you want the JSON column to be visible again, you'll need to change the column's visibility to **Everywhere**.
8. Scroll down and click on the **Re-scan this field**.

![Unfolded JSON setting](./images/unfold-json-setting.png)

## For JSON unfolding to work, the column's data type must be JSON

For example, if you upload a CSV with JSON in it, you might need to update the data/type in the database. Note that you can't edit the data type via Metabase; you can only change its field type. So even if the field type in Metabase is `Field containing JSON`, if the data/type isn't `JSON`, Metabase won't give you the option to unfold the column. You'll need to change the column type in the database itself.

## Databases that support JSON unfolding

- [PostgreSQL](../databases/connections/postgresql.md)
- [MySQL](../databases/connections/mysql.md)
6 changes: 5 additions & 1 deletion docs/data-modeling/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Metabase provides tools for organizing your data and making it easier for people

## [Models](./models.md)

Models curate data from another table or tables from the same database to anticipate the kinds of questions people will ask of the data. You can think of them as derived tables, or a special kind of saved question meant to be used as the starting point for new questions.
Models curate data from another table or tables from the same database to anticipate the kinds of questions people will ask of the data. You can think of them as derived tables, or a special kind of saved question meant to be used as the starting point for new questions.

## [Table metadata admin settings](./metadata-editing.md)

Expand All @@ -22,6 +22,10 @@ Field types dictate how Metabase displays its data, as well as the column’s sp

Define formatting and display defaults for numbers, currencies, datetimes, and more.

## [Working with JSON](./json-unfolding.md)

Metabase can unfold JSON columns into their component fields, which you can then filter on using the query builder.

## [Creating segments and metrics](./segments-and-metrics.md)

Admins can define segments to create official filters for your data, and metrics for official aggregations.
12 changes: 0 additions & 12 deletions docs/installation-and-operation/upgrading-metabase.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ See [Backing up Metabase application data](backing-up-metabase-application-data.

Steps differ depending on whether you're running the JAR or a Docker image.

- [Upgrading Metabase](#upgrading-metabase)
- [Backing up your application database](#backing-up-your-application-database)
- [Swapping in the new Metabase version](#swapping-in-the-new-metabase-version)
- [Upgrading a JAR running locally](#upgrading-a-jar-running-locally)
- [Upgrading a JAR running in production as a service](#upgrading-a-jar-running-in-production-as-a-service)
- [Upgrading the Docker image](#upgrading-the-docker-image)
- [Upgrading from older versions of Metabase](#upgrading-from-older-versions-of-metabase)
- [Upgrading Metabase Cloud](#upgrading-metabase-cloud)
- [Upgrading Metabase on other platforms](#upgrading-metabase-on-other-platforms)
- [Rolling back an upgrade](#rolling-back-an-upgrade)
- [Using the migrate down command](#using-the-migrate-down-command)

### Upgrading a JAR running locally

If you're running the JVM Jar file directly:
Expand Down
49 changes: 48 additions & 1 deletion e2e/support/helpers/e2e-snowplow-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,58 @@ export const expectGoodSnowplowEvent = (eventData, count = 1) => {
"micro/good",
({ body }) =>
body.filter(snowplowEvent =>
_.isMatch(snowplowEvent?.event?.unstruct_event?.data?.data, eventData),
isDeepMatch(
snowplowEvent?.event?.unstruct_event?.data?.data,
eventData,
),
).length === count,
).should("be.ok");
};

export function isDeepMatch(objectOrValue, partialObjectOrValue) {
if (isMatcher(partialObjectOrValue)) {
return partialObjectOrValue(objectOrValue);
}

const bothAreNotObjects =
// Check null because typeof null === "object"
objectOrValue == null ||
partialObjectOrValue == null ||
typeof objectOrValue !== "object" ||
typeof partialObjectOrValue !== "object";

// Exit condition when calling recursively
if (bothAreNotObjects) {
return objectOrValue === partialObjectOrValue;
}

for (const [key, value] of Object.entries(partialObjectOrValue)) {
if (Array.isArray(value)) {
if (!isArrayDeepMatch(objectOrValue[key], value)) {
return false;
}
} else if (!isDeepMatch(objectOrValue[key], value)) {
return false;
}
}

return true;
}

function isMatcher(value) {
return typeof value === "function";
}

function isArrayDeepMatch(array, partialArray) {
for (const index in partialArray) {
if (!isDeepMatch(array[index], partialArray[index])) {
return false;
}
}

return true;
}

export const expectGoodSnowplowEvents = count => {
retrySnowplowRequest("micro/good", ({ body }) => body.length >= count)
.its("body")
Expand Down
5 changes: 5 additions & 0 deletions e2e/support/helpers/e2e-ui-elements-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export function popover() {
return cy.get(POPOVER_ELEMENT);
}

export function mantinePopover() {
const MANTINE_POPOVER = "[data-popover=mantine-popover]";
return cy.get(MANTINE_POPOVER).should("be.visible");
}

const HOVERCARD_ELEMENT = ".emotion-HoverCard-dropdown[role='dialog']";

export function hovercard() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describeEE("scenarios > embedding > questions > downloads", () => {
});

cy.log("Disable downloads");
cy.findByLabelText("Enable users to download data from this embed")
cy.findByLabelText("Download data")
.as("allow-download-toggle")
.should("be.checked");

Expand Down
4 changes: 3 additions & 1 deletion e2e/test/scenarios/embedding/embedding-smoketests.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ describe("scenarios > embedding > smoke tests", { tags: "@OSS" }, () => {
cy.findByRole("tab", { name: "Appearance" }).click();

cy.findByText("Background");
cy.findByText("Dashboard title");
cy.findByText(
object === "dashboard" ? "Dashboard title" : "Question title",
);
cy.findByText("Border");
cy.findByText(
(_, element) =>
Expand Down

0 comments on commit 26e2dfe

Please sign in to comment.