# Path: orangecontrib/spark/base/shared_spark_context.py
# class SharedSparkContext:
#     _sc = None
#     _hc = None
# 
#     @property
#     def sc(self):
#         return SharedSparkContext._sc
# 
#     @sc.setter
#     def sc(self, val):
#         SharedSparkContext._sc = val
# 
#     @property
#     def hc(self):
#         return SharedSparkContext._hc
# 
#     @hc.setter
#     def hc(self, val):
#         SharedSparkContext._hc = val
# 
# Path: orangecontrib/spark/utils/data_utils.py
# def pandas_to_orange(df):
#     domain, attributes, metas = construct_domain(df)
#     orange_table = Orange.data.Table.from_numpy(domain = domain, X = df[attributes].values, Y = None, metas = df[metas].values, W = None)
#     return orange_table
# 
# def format_sql(str_sql):
#     return str(sqlparse.format(str_sql, reindent = True, keyword_case = 'upper'))


import pyspark
from Orange.widgets import widget, gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from PyQt4 import QtCore
from PyQt4.QtGui import (
    QSizePolicy, QSplitter, QPlainTextEdit
)
from orangecontrib.spark.base.shared_spark_context import SharedSparkContext
from orangecontrib.spark.utils.data_utils import pandas_to_orange, format_sql
    def activateLoadedSettings(self):
        self.query = self.lastQuery

    def setInfo(self, info):
        pass
        # for (i, s) in enumerate(info):
        #    self.info[i].setText(s)

    def setMeta(self):
        pass
        # domain = self.data.domain
        # s = "Attrs:\n    " + "\n    ".join([str(i) for i in domain.attributes]) + "\n" + "Class:" + str(domain.classVar)
        # self.domainLabel.setText(s)
        # for i in domain.getmetas():
        # self.propertyCheckBoxes[i].set()

    # Execute a query, create data from it and send it over the data channel
    def executeQuery(self):
        if not self.sc or not self.hc:
            return

        query = self.queryTextEdit.toPlainText()

        if query is None:
            return None

        self.out_df = self.hc.sql(query)
        self.lastQuery = query
        self.send("DataFrame", self.out_df)


# Path: orangecontrib/spark/base/shared_spark_context.py
# class SharedSparkContext:
#     _sc = None
#     _hc = None
# 
#     @property
#     def sc(self):
#         return SharedSparkContext._sc
# 
#     @sc.setter
#     def sc(self, val):
#         SharedSparkContext._sc = val
# 
#     @property
#     def hc(self):
#         return SharedSparkContext._hc
# 
#     @hc.setter
#     def hc(self, val):
#         SharedSparkContext._hc = val
# 
# Path: orangecontrib/spark/utils/data_utils.py
# def pandas_to_orange(df):
#     domain, attributes, metas = construct_domain(df)
#     orange_table = Orange.data.Table.from_numpy(domain = domain, X = df[attributes].values, Y = None, metas = df[metas].values, W = None)
#     return orange_table
# 
# def format_sql(str_sql):
#     return str(sqlparse.format(str_sql, reindent = True, keyword_case = 'upper'))


# Path: orangecontrib/spark/widgets/data/spark_sql_dataframe.py
import pyspark
from Orange.widgets import widget, gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from PyQt4 import QtCore
from PyQt4.QtGui import (
    QSizePolicy, QSplitter, QPlainTextEdit
)
from orangecontrib.spark.base.shared_spark_context import SharedSparkContext
from orangecontrib.spark.utils.data_utils import pandas_to_orange, format_sql

    def activateLoadedSettings(self):
        self.query = self.lastQuery

    def setInfo(self, info):
        pass
        # for (i, s) in enumerate(info):
        #    self.info[i].setText(s)

    def setMeta(self):
        pass
        # domain = self.data.domain
        # s = "Attrs:\n    " + "\n    ".join([str(i) for i in domain.attributes]) + "\n" + "Class:" + str(domain.classVar)
        # self.domainLabel.setText(s)
        # for i in domain.getmetas():
        # self.propertyCheckBoxes[i].set()

    # Execute a query, create data from it and send it over the data channel
    def executeQuery(self):
        if not self.sc or not self.hc:
            return

        query = self.queryTextEdit.toPlainText()

        if query is None:
            return None

        self.out_df = self.hc.sql(query)
        self.lastQuery = query
        self.send("DataFrame", self.out_df)


    def format_sql(self):