# 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 os.path
import pyodbc
import pandas as pd
import pandas.io.sql as psql
import Orange
from Orange.widgets.widget import OWWidget
from orangecontrib.spark.utils.data_utils import pandas_to_orange, format_sql
from PyQt4.QtGui import (
    QListView, QSizePolicy, QApplication, QAction, QKeySequence,
    QGraphicsLineItem, QSlider, QPainterPath, QSplitter, QPlainTextEdit, QFileDialog
)
from PyQt4 import QtCore
from Orange.widgets import widget, gui, settings
        for fw in self.allFileWidgets:
            if fw != self and getattr(fw, "dataDomain", None):
                for var in domain:
                    if var in fw.dataDomain:
                        return True
        return False

    # Execute a query, create data from it and send it over the data channel
    def executeQuery(self, query = None, throughReload = 0, DK = None, DC = None):

        self.connectDB()
        query = self.queryTextEdit.toPlainText()

        if query is None:
            query = str(self.queryTextEdit.toPlainText())
        # try:
        self.pandas = psql.read_sql_query(query, self.cnxn)
        # except Exception:
        #    self.setInfo(('Query failed:', str('')))
        #    df = pd.DataFrame()

        self.data = convert_dataframe_to_orange(self.pandas)

        self.send("Data", self.data)
        self.send("Pandas", self.pandas)
        self.setInfo(('Query returned', 'Read ' + str(len(self.data)) + ' examples!'))
        self.send("Feature Definitions", self.data.domain)
        self.setMeta()
        self.lastQuery = query


# 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/odbc_table.py
import os.path
import pyodbc
import pandas as pd
import pandas.io.sql as psql
import Orange
from Orange.widgets.widget import OWWidget
from orangecontrib.spark.utils.data_utils import pandas_to_orange, format_sql
from PyQt4.QtGui import (
    QListView, QSizePolicy, QApplication, QAction, QKeySequence,
    QGraphicsLineItem, QSlider, QPainterPath, QSplitter, QPlainTextEdit, QFileDialog
)
from PyQt4 import QtCore
from Orange.widgets import widget, gui, settings

        for fw in self.allFileWidgets:
            if fw != self and getattr(fw, "dataDomain", None):
                for var in domain:
                    if var in fw.dataDomain:
                        return True
        return False

    # Execute a query, create data from it and send it over the data channel
    def executeQuery(self, query = None, throughReload = 0, DK = None, DC = None):

        self.connectDB()
        query = self.queryTextEdit.toPlainText()

        if query is None:
            query = str(self.queryTextEdit.toPlainText())
        # try:
        self.pandas = psql.read_sql_query(query, self.cnxn)
        # except Exception:
        #    self.setInfo(('Query failed:', str('')))
        #    df = pd.DataFrame()

        self.data = convert_dataframe_to_orange(self.pandas)

        self.send("Data", self.data)
        self.send("Pandas", self.pandas)
        self.setInfo(('Query returned', 'Read ' + str(len(self.data)) + ' examples!'))
        self.send("Feature Definitions", self.data.domain)
        self.setMeta()
        self.lastQuery = query


    def format_sql(self):