# 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 __init__(self):
        super().__init__()
        gui.label(self.controlArea, self, "Spark DataFrame")
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        self.allSQLSelectWidgets.append(self)  # set default settings
        self.domain = None

        self.queryFile = None
        self.query = ''
        if self.lastQuery is not None:
            self.query = self.lastQuery

        # query
        self.splitCanvas = QSplitter(QtCore.Qt.Vertical, self.mainArea)
        self.mainArea.layout().addWidget(self.splitCanvas)

        self.textBox = gui.widgetBox(self, 'SparkSQL')
        self.splitCanvas.addWidget(self.textBox)
        self.queryTextEdit = QPlainTextEdit(self.query, self)
        self.textBox.layout().addWidget(self.queryTextEdit)

        self.selectBox = gui.widgetBox(self.controlArea, "Select statement")
        self.selectBox.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding))
        gui.button(self.selectBox, self, 'format SQL!', callback = self.format_sql, disabled = 0)
        gui.button(self.selectBox, self, 'execute!', callback = self.executeQuery, disabled = 0)

        # info
        self.infoBox = gui.widgetBox(self.controlArea, "Info")
        self.info = []
        self.info.append(gui.label(self.infoBox, self, 'No data loaded.'))

# 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 __init__(self):
        super().__init__()
        gui.label(self.controlArea, self, "Spark DataFrame")
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        self.allSQLSelectWidgets.append(self)  # set default settings
        self.domain = None

        self.queryFile = None
        self.query = ''
        if self.lastQuery is not None:
            self.query = self.lastQuery

        # query
        self.splitCanvas = QSplitter(QtCore.Qt.Vertical, self.mainArea)
        self.mainArea.layout().addWidget(self.splitCanvas)

        self.textBox = gui.widgetBox(self, 'SparkSQL')
        self.splitCanvas.addWidget(self.textBox)
        self.queryTextEdit = QPlainTextEdit(self.query, self)
        self.textBox.layout().addWidget(self.queryTextEdit)

        self.selectBox = gui.widgetBox(self.controlArea, "Select statement")
        self.selectBox.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding))
        gui.button(self.selectBox, self, 'format SQL!', callback = self.format_sql, disabled = 0)
        gui.button(self.selectBox, self, 'execute!', callback = self.executeQuery, disabled = 0)

        # info
        self.infoBox = gui.widgetBox(self.controlArea, "Info")
        self.info = []
        self.info.append(gui.label(self.infoBox, self, 'No data loaded.'))

        self.info.append(gui.label(self.infoBox, self, ''))