0

I am new to Flask. I have a Hive table called database_table with following fields:

id field_id table_name schema_name
1 1 employee_table employee
2 2 department_table employeee
3 3 statistics_table employeee

Based on this database_table when we select field_id based on that we should see the results of following of table in UI using Flask code example. When we select field_id =1 then it should pick the table name from database_table and query the employee_Table and display the results in UI.

I have the following code:

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/<limit>')
    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)
6
  • 3
    What is your question? Commented Jan 20 at 8:32
  • 1
    @snakecharmerb Based on this database_table when we select field_id based on that we should see the results of following of table in UI using Flask code example. When we select field_id =1 then it should pick the table name from database_table and query the employee_Table and display the results in UI. I think the question is on how to do that Commented Jan 21 at 1:47
  • 2
    @user5127 "How do I build a web UI" given just the backend code is too broad question, in my view. Commented Jan 21 at 6:55
  • 1
    @snakecharmerb I guess he needs to provide what he tried in the UI part Commented Jan 21 at 20:40
  • 1
    I would also like to note that your post is missing the question part. What are you trying to do? What is the problem you are trying to solve? Commented Jan 22 at 8:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.