-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update origin: Add ratio support and a number of algorithm improvement
- Loading branch information
Showing
75 changed files
with
3,125 additions
and
1,746 deletions.
There are no files selected for viewing
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
Binary file not shown.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from orjson import orjson | ||
|
||
|
||
def build_error_response(error: str) -> str: | ||
return orjson.dumps({ | ||
'error': error | ||
}) |
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,7 +1 @@ | ||
from flask import Blueprint | ||
from flask_cors import CORS, cross_origin | ||
|
||
bp = Blueprint('data-source', __name__, url_prefix='/api/data-source') | ||
CORS(bp) | ||
|
||
from app.data_source import routes |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import json | ||
|
||
from flask_appbuilder import expose | ||
from flask_appbuilder.api import BaseApi | ||
from google.api_core.exceptions import NotFound | ||
from google.auth.exceptions import GoogleAuthError | ||
from loguru import logger | ||
from orjson import orjson | ||
|
||
from app.common.request_utils import build_error_response | ||
from app.data_source.bigquery.bigquery_source import BigquerySource | ||
|
||
|
||
class BigQuerySourceApi(BaseApi): | ||
resource_name = 'source/bigquery' | ||
bigquery_source = BigquerySource() | ||
|
||
@expose('/schema/<full_name>', methods=['GET']) | ||
def get_schema(self, full_name: str): | ||
try: | ||
return orjson.dumps(self.bigquery_source.get_schema(full_name)) | ||
except NotFound as e: | ||
return build_error_response('Table not found.'), 404 | ||
except GoogleAuthError as e: | ||
return build_error_response('Auth failed.'), 403 | ||
except Exception as e: | ||
logger.exception(e) | ||
return build_error_response('Internal server error.'), 500 | ||
|
||
@expose('/dataset', methods=['GET']) | ||
def list_datasets(self): | ||
try: | ||
return orjson.dumps(self.bigquery_source.list_dataset()) | ||
except GoogleAuthError as e: | ||
return build_error_response(str(e)), 403 | ||
except Exception as e: | ||
logger.exception(e) | ||
return json.dumps({'error': 'Internal server error.'}), 500 |
4 changes: 2 additions & 2 deletions
4
.../data_source/datasource/bigquerySource.py → ...p/data_source/bigquery/bigquery_source.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
This file was deleted.
Oops, something went wrong.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from flask import request | ||
from flask_appbuilder.api import BaseApi, expose | ||
from loguru import logger | ||
from orjson import orjson | ||
|
||
from app.common.request_utils import build_error_response | ||
from app.data_source.file.file_source import FileSource | ||
from app.data_source.file.file_upload_service import FileUploadService | ||
|
||
|
||
class FileSourceApi(BaseApi): | ||
resource_name = 'source/file' | ||
|
||
@expose('/schema', methods=['POST']) | ||
def load_schema(self): | ||
logger.info("Loading file from request") | ||
if 'file' not in request.files: | ||
return build_error_response("No file part in the request"), 400 | ||
file = request.files['file'] | ||
if file.filename == '': | ||
return build_error_response("No selected file"), 400 | ||
|
||
try: | ||
logger.info("Saving file to disk") | ||
file_data = file.read() | ||
output_dir = "/tmp/dsensei" | ||
|
||
file_processor = FileUploadService() | ||
md5 = file_processor.save_file_with_md5(file_data, output_dir) | ||
|
||
schema = FileSource(md5).load_schema() | ||
return orjson.dumps(schema), 200 | ||
except FileExistsError as e: | ||
return build_error_response(str(e)), 409 | ||
except Exception as e: | ||
logger.exception(e) | ||
return build_error_response(str(e)), 500 |
Oops, something went wrong.