osinachi_chukwujama
06/07/2022, 10:12 AMtime=2022-06-07 09:28:16 name=tap-jsonplaceholder level=WARNING message=Property 'response_code' was present in the 'comments' stream but not found in catalog schema. Ignoring.
time=2022-06-07 09:28:16 name=tap-jsonplaceholder level=WARNING message=Property 'results' was present in the 'comments' stream but not found in catalog schema. Ignoring.
{"type": "RECORD", "stream": "comments", "record": {}, "time_extracted": "2022-06-07T09:28:16.214634Z"}
time=2022-06-07 09:28:16 name=tap-jsonplaceholder level=INFO message=INFO METRIC: {'type': 'counter', 'metric': 'record_count', 'value': 1, 'tags': {'stream': 'comments'}}
{"type": "STATE", "value": {"bookmarks": {"comments": {}}}}
Here's my streams.py file
from pathlib import Path
from typing import Any, Dict, Optional, Union, List, Iterable
from singer_sdk import typing as th # JSON Schema typing helpers
from tap_jsonplaceholder.client import jsonplaceholderStream
class CommentsStream(jsonplaceholderStream):
primary_keys = ["id"]
path = '/comments'
name = "comments"
schema = th.PropertiesList(
th.Property("postId", th.StringType),
th.Property("id", th.StringType),
th.Property("name", th.StringType),
th.Property("email", th.StringType),
th.Property("body", th.StringType),
).to_dict()
And here's my tap.py file
"""jsonplaceholder tap class."""
from typing import List
from singer_sdk import Tap, Stream
from singer_sdk import typing as th # JSON schema typing helpers
# TODO: Import your custom stream types here:
from tap_jsonplaceholder.streams import (
jsonplaceholderStream,
CommentsStream
)
# TODO: Compile a list of custom stream types here
# OR rewrite discover_streams() below with your custom logic.
STREAM_TYPES = [
CommentsStream
]
class Tapjsonplaceholder(Tap):
"""jsonplaceholder tap class."""
name = "tap-jsonplaceholder"
config_jsonschema = th.PropertiesList(
th.Property(
"api_url",
th.StringType,
default="<https://jsonplaceholder.typicode.com>",
description="The json placeholder API"
),
).to_dict()
def discover_streams(self) -> List[Stream]:
"""Return a list of discovered streams."""
return [stream_class(tap=self) for stream_class in STREAM_TYPES]
Here's the Github repo containing the tap code: https://github.com/vicradon/tap-jsonplaceholderchristoph
06/07/2022, 10:37 AMosinachi_chukwujama
06/07/2022, 10:38 AMReuben (Matatika)
06/07/2022, 11:47 AMresponse_code
and results
properties, which you do not define in CommentsStream.schema
. If you want to include them, add the corresponding th.Property
instances:
schema = th.PropertiesList(
th.Property("postId", th.StringType),
th.Property("id", th.StringType),
th.Property("name", th.StringType),
th.Property("email", th.StringType),
th.Property("body", th.StringType),
th.Property("response_code", <type>), // assuming `response_code` in an integer, use `th.IntegerType`
th.Property("results", <type>),
).to_dict()
osinachi_chukwujama
06/07/2022, 1:03 PMosinachi_chukwujama
06/07/2022, 1:55 PMReuben (Matatika)
06/07/2022, 2:26 PMTapjsonplaceholder
class and then access the config in your stream classes with self.config
.osinachi_chukwujama
06/07/2022, 2:28 PM