Skip to content

Commit

Permalink
data-process - create endpoints vol9
Browse files Browse the repository at this point in the history
  • Loading branch information
erayerturk committed May 19, 2024
1 parent 0ccbb7f commit 2c99c4d
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions superset/dvt_dataprocess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ def __init__(self):
self.connection_string = 'postgresql://examples:examples@db:5432/examples'

def handle_request(self, func):
# try:
payload = request.json
if "selected_columns" not in payload or "table_name" not in payload:
return jsonify({"error": "Missing required fields in the payload"}), 400
engine = get_engine(self.connection_string)
session = create_session(engine)
result = func(payload, engine, session)
session.commit()
return result
# except Exception as e:
# return jsonify({"error": str(e)}), 500
# finally:
# session.close()
try:
payload = request.json
if "selected_columns" not in payload or "table_name" not in payload:
return jsonify({"error": "Missing required fields in the payload"}), 400
engine = get_engine(self.connection_string)
session = create_session(engine)
result = func(payload, engine, session)
session.commit()
return result
except Exception as e:
return jsonify({"error": str(e)}), 500
finally:
session.close()

@expose("/outlier-analysis", methods=("POST",))
@event_logger.log_this
Expand All @@ -83,14 +83,12 @@ def outlier_analysis_impl(self, payload, engine, session):
try:
outliers_table = Table(outliers_table_name, metadata, autoload=True, autoload_with=engine)
except NoSuchTableError:
# Define the table structure
outliers_table = Table(
outliers_table_name,
metadata,
Column('id', Integer, primary_key=True, autoincrement=True),
*(Column(column, Float) for column in selected_columns)
)
# Create the table in the database
metadata.create_all(engine)
outliers_table = Table(outliers_table_name, metadata, autoload=True, autoload_with=engine)

Expand Down

0 comments on commit 2c99c4d

Please sign in to comment.