Zeigen Sie die Ergebnisse der Hive-Tabelle in der Benutzeroberfläche mithilfe von flask anPython

Python-Programme
Guest
 Zeigen Sie die Ergebnisse der Hive-Tabelle in der Benutzeroberfläche mithilfe von flask an

Post by Guest »

Ich bin neu bei Flask.
Ich habe eine Hive-Tabelle namens „database_table“ mit den folgenden Feldern:

Code: Select all

id,field_id,table_name,schema_name
1,1,employee_table,employee
2,2,department_table,employeee
3,3,statistics_table,employeee
Basierend auf dieser Datenbanktabelle, wenn wir darauf basierend die Feld-ID auswählen, sollten wir die Ergebnisse der folgenden Tabelle in der Benutzeroberfläche unter Verwendung des Flask-Codebeispiels sehen. Wenn wir field_id =1 auswählen, sollte es den Tabellennamen aus „database_table“ auswählen, die „employee_Table“ abfragen und die Ergebnisse in der Benutzeroberfläche anzeigen.
I habe den folgenden Code:

Code: Select all

from pyhive import hive
from flask import current_app

try:
from flask import _app_ctx_stack as stack
except ImportError:
from flask import _request_ctx_stack as stack

class Hive(object):

def __init__(self, app=None):
self.app = app
if app is not None:
self.init_app(app)

def init_app(self, app):
# Use the newstyle teardown_appcontext if it's available,
# otherwise fall back to the request context
if hasattr(app, 'teardown_appcontext'):
app.teardown_appcontext(self.teardown)
else:
app.teardown_request(self.teardown)

def connect(self):
return hive.connect(current_app.config['HIVE_DATABASE_URI'], database="orc")

def teardown(self, exception):
ctx = stack.top
if hasattr(ctx, 'hive_db'):
ctx.hive_db.close()
return None

@property
def connection(self):
ctx = stack.top
if ctx is not None:
if not hasattr(ctx, 'hive_db'):
ctx.hive_db = self.connect()
return ctx.hive_db

@blueprint.route('/hive/')
def connect_to_hive(limit):
cur = hive.connection.cursor()
query = "select table_name from database_table where field_id=1 {0}".format(limit)
cur.execute(query)
res = cur.fetchall()
return jsonify(data=res)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post