-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wed 2 Oct 12:42 am #19 - Added source class fror near GCP BigQuery
- Loading branch information
1 parent
aa99a0d
commit b97aa0b
Showing
3 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
28 changes: 21 additions & 7 deletions
28
local-data-platform/local_data_platform/source/gcp/gcp_bigquery/source_gcp_bigquery.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
from google.cloud import bigquery | ||
from source.gcp.gcp_connection import GCPBigQueryConnection | ||
|
||
class SourceGCPBigQuery : | ||
class SourceGCPBigQuery: | ||
""" | ||
A class to interact with Google BigQuery. | ||
client : GCPBigQueryConnection | ||
An instance of GCPBigQueryConnection to interact with BigQuery. | ||
""" | ||
def __init__(self): | ||
self.client = GCPBigQueryConnection('path/to/credentials.json', 'your-project-id') | ||
|
||
def fetch_data(query): | ||
client = bigquery.Client() | ||
query_job = client.query(query) | ||
return query_job.to_dataframe() | ||
|
||
def fetch_data(self, query): | ||
""" | ||
Executes a given SQL query on Google BigQuery and returns the result as a pandas DataFrame. | ||
Args: | ||
query (str): The SQL query to be executed. | ||
Returns: | ||
pandas.DataFrame: The result of the query as a DataFrame. | ||
""" | ||
query_job = self.client.query(query) | ||
return query_job.to_dataframe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 16 additions & 4 deletions
20
local-data-platform/local_data_platform/source/near/source_near_gcp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
from local_data_platform.source.gcp.gcp_bigquery import SourceGCPBigQuery | ||
from local_data_platform.source.gcp.gcp_bigquery.source_gcp_bigquery import SourceGCPBigQuery | ||
""" | ||
This module defines the Source_Near_GCP class, which inherits from SourceGCPBigQuery | ||
and provides functionality to fetch transaction data from the NEAR protocol on Google Cloud Platform. | ||
Classes: | ||
Source_Near_GCP: A class to fetch NEAR protocol transaction data from GCP BigQuery. | ||
Methods: | ||
fetch_near_transaction(self): | ||
Fetches NEAR protocol transaction data from the previous day. | ||
Returns: | ||
DataFrame: A pandas DataFrame containing the transaction data. | ||
""" | ||
class Source_Near_GCP(SourceGCPBigQuery): | ||
|
||
def fetch_near_transaction(self): | ||
query = """ | ||
SELECT * | ||
FROM `nearprotocol.near.transaction` | ||
WHERE DATE(block_timestamp) = DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) | ||
FROM `bigquery-public-data.crypto_near.transactions` | ||
LIMIT 1000; | ||
""" | ||
return self.fetch(query) | ||
return self.fetch_data(query) |