In Cloud Storage abfragen
In diesem Leitfaden wird erläutert, wie Daten in Cloud Storage gespeichert werden, sowohl im Rohformat als auch in verarbeiteten Formaten.
Rohdaten
In der Manufacturing Data Engine (MDE) werden alle empfangenen Nachrichten im Rohformat gespeichert, ohne dass sie verarbeitet werden. Das ist sowohl aus Archivierungsgründen als auch für die erneute Verarbeitung von Daten bei Konfigurations- oder Systemfehlern nützlich.
Rohdaten werden im AVRO-Format mit dem folgenden Schema gespeichert:
{
"type" : "record",
"name" : "AvroPubsubMessageRecord",
"namespace" : "com.google.cloud.industry.manufacturing.sfp.datalake.core",
"fields" : [ {
"name" : "attributes",
"type" : {
"type" : "map",
"values" : "string"
}
}, {
"name" : "message",
"type" : {
"type" : "bytes",
"java-class" : "[B"
}
}, {
"name" : "messageId",
"type" : "string"
}, {
"name" : "timestamp",
"type" : "long"
} ]
Das Schema besteht aus den folgenden Werten:
- attributes: Speichert die Pub/Sub-Nachrichtenattributzuordnung.
- message: Speichert die Rohdaten der Nachricht, wie sie im Pub/Sub-Thema
input-messagesempfangen wurde. - messageId: Die ID, die von Pub/Sub beim Empfang der Nachricht festgelegt wird. Sie wird in alle Senken geschrieben, um die Herkunft der Daten nachvollziehen zu können.
- timestamp: Zeitpunkt, zu dem die Nachricht von Pub/Sub empfangen wurde.
Die Daten werden standardmäßig in einem Cloud Storage-Bucket namens <project-id>-raw gespeichert. Und dann in einem Ordner für die Version, in diesem Fall 1.3.
Die Dateien werden dann mit dem Format dt=YYYY-MM-DD nach Tag partitioniert.
Nachrichten werden in 10-Minuten-Fenstern gruppiert und in jedem Fenster werden 10 Dateien geschrieben. Diese Daten werden verwendet, um die Dateinamen zu erstellen. Das folgende Skript zeigt ein Beispiel dafür:
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-00-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-01-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-02-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-03-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-04-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-05-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-06-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-07-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-08-of-10avro
gs://<project-id>-raw/v1.3/dt=2023-08-08/gcsoutput2023-08-08T09:20:00.000Z-2023-08-08T09:30:00.000Z-pane-0-last-09-of-10avro
Lesezugriff auf BigQuery
In den folgenden Abschnitten wird beschrieben, wie Daten aus BigQuery gelesen werden.
Verarbeitete Daten
Sobald Daten von MDE verarbeitet wurden, können sie konfiguriert werden, um in Cloud Storage gespeichert zu werden.
Standardmäßig werden die Daten in einem Bucket mit dem Namen <project-id>-gcs-ingestion gespeichert.
Die Daten werden dann in einem Ordner für die Version gespeichert, in diesem Fall v1.3. Jeder Typ wird in einem eigenen Ordner (default-discrete-records,
default-numeric-records, etc) gespeichert. Schließlich werden die Dateien nach Tag partitioniert, wobei das Format dt=YYYY-MM-DD verwendet wird.
Wie bei Rohdaten werden Nachrichten in 10-Minuten-Fenstern gruppiert und in jedem Fenster werden 10 Dateien geschrieben. Diese Daten werden verwendet, um die Dateinamen zu erstellen, z. B.:
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00000-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00001-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00002-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00003-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00004-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00005-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00006-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00007-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00008-of-00010.avro
gs://<project-id>-gcs-ingestion/v1.3/default-discrete-records/dt=2023-08-08/gcsoutput2023-08-08T09:40:00.000Z-2023-08-08T09:50:00.000Z-00009-of-00010.avro
Es gibt ein anderes Schema, das sich für jeden Archetyp nur geringfügig unterscheidet. Daher wird für jeden Typ das entsprechende Schema verwendet. Betrachten Sie die folgenden Beispiele:
NumericDataSeries Archetypschema:
{
"type": "record",
"namespace": "com.google.cloud.industry.manufacturing.sfp.datalake.storage.gcs",
"name": "NumericDataSeriesGCSObject",
"fields": [
{
"name": "id",
"type": "string",
"doc": "Unique record id"
},
{
"name": "tag_name",
"type": "string",
"doc": "Name of the tag"
},
{
"name": "type_name",
"type": "string"
},
{
"name": "type_version",
"type": "int"
},
{
"name": "embedded_metadata",
"type": ["null", "string"],
"default": null
},
{
"name": "materialized_cloud_metadata",
"type": ["null", "string"],
"default": null
},
{
"name": "cloud_metadata_ref",
"type": ["null", "string"],
"default": null
},
{
"name": "source_message_id",
"type": "string"
},
{
"name": "event_timestamp",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "value",
"type": "double"
}
]
}
DiscreteDataSeries Archetypschema:
{
"type": "record",
"name": "DiscreteDataSeriesGCSObject",
"namespace": "com.google.cloud.industry.manufacturing.sfp.datalake.storage.gcs",
"fields": [
{
"name": "id",
"type": {
"type": "string",
"avro.java.string": "String"
},
"doc": "Unique record id"
},
{
"name": "tag_name",
"type": {
"type": "string",
"avro.java.string": "String"
},
"doc": "Name of the tag"
},
{
"name": "type_name",
"type": {
"type": "string",
"avro.java.string": "String"
}
},
{
"name": "type_version",
"type": "int"
},
{
"name": "embedded_metadata",
"type": [
"null",
{
"type": "string",
"avro.java.string": "String"
}
],
"default": null
},
{
"name": "materialized_cloud_metadata",
"type": [
"null",
{
"type": "string",
"avro.java.string": "String"
}
],
"default": null
},
{
"name": "cloud_metadata_ref",
"type": [
"null",
{
"type": "string",
"avro.java.string": "String"
}
],
"default": null
},
{
"name": "source_message_id",
"type": {
"type": "string",
"avro.java.string": "String"
}
},
{
"name": "event_timestamp",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "data",
"type": {
"type": "string",
"avro.java.string": "String"
}
}
]
}
ContinuousDataSeries Archetypschema:
{
"type": "record",
"namespace": "com.google.cloud.industry.manufacturing.sfp.datalake.storage.gcs",
"name": "ContinuousDataSeriesGCSObject",
"fields": [
{
"name": "id",
"type": "string",
"doc": "Unique record id"
},
{
"name": "tag_name",
"type": "string",
"doc": "Name of the tag"
},
{
"name": "type_name",
"type": "string"
},
{
"name": "type_version",
"type": "int"
},
{
"name": "embedded_metadata",
"type": ["null", "string"],
"default": null
},
{
"name": "materialized_cloud_metadata",
"type": ["null", "string"],
"default": null
},
{
"name": "cloud_metadata_ref",
"type": ["null", "string"],
"default": null
},
{
"name": "source_message_id",
"type": "string"
},
{
"name": "event_timestamp_start",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "event_timestamp_end",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "data",
"type": "string"
},
{
"name": "duration",
"type": "long"
}
]
}