Exemplo n.º 1
0
def make_sql_column_string(table_source, dataset, *args):
    '''
    Return string with all column names to return with SQL query, comma separated.

    Arguments:
    - table_source: SkyServer table name to draw from
    - dataset: SkyServer dataset to draw from
    - (optional) column features to drop, if any. Can be single feature (eg 'cont') and multiple features
    '''
    try:
        columns = SkyQuery.listTableColumns(tableName=table_source,
                                            datasetName=dataset)
    except Exception as err:
        if str(err) == 'User token is not defined. First log into SciServer.':
            token = login()
            columns = SkyQuery.listTableColumns(tableName=table_source,
                                                datasetName=dataset)
        else:
            raise err
    column_names = [col['name'] for col in columns]
    if len(args) > 0:
        column_names = drop_side_or_cont_(column_names)
    id_index, subclass_index = column_names.index(
        'SPECOBJID'), column_names.index('SUBCLASS')
    column_names[:0] = [
        column_names.pop(id_index),
        column_names.pop(subclass_index)
    ]
    column_string = ', '.join(column_names)
    return column_string
Exemplo n.º 2
0
    def test_SkyQuery_uploadTable_getTable_getTableInfo_listTableColumns_dropTable(
            self):
        try:
            result = SkyQuery.dropTable(tableName=SkyQuery_TestTableName,
                                        datasetName="MyDB")
        except:
            pass

        result = SkyQuery.uploadTable(uploadData=SkyQuery_TestTableCSV,
                                      tableName=SkyQuery_TestTableName,
                                      datasetName="MyDB",
                                      format="csv")
        self.assertEqual(result, True)

        table = SkyQuery.getTable(tableName=SkyQuery_TestTableName,
                                  datasetName="MyDB",
                                  top=10)
        self.assertEqual(SkyQuery_TestTableCSVdownloaded,
                         table.to_csv(index=False))

        info = SkyQuery.getTableInfo(tableName="webuser." +
                                     SkyQuery_TestTableName,
                                     datasetName="MyDB")

        columns = SkyQuery.listTableColumns(tableName="webuser." +
                                            SkyQuery_TestTableName,
                                            datasetName="MyDB")

        result = SkyQuery.dropTable(tableName=SkyQuery_TestTableName,
                                    datasetName="MyDB")
        self.assertEqual(result, True)
print(tables)


# In[ ]:

#get dataset table info:

info = SkyQuery.getTableInfo(tableName="webuser." + SkyQuery_TestTableName, datasetName="MyDB")
print(info)


# In[ ]:

#get dataset table columns info

columns = SkyQuery.listTableColumns(tableName="webuser." + SkyQuery_TestTableName, datasetName="MyDB")
print(columns)


# In[ ]:

#drop (or delete) table from dataset.

result = SkyQuery.dropTable(tableName=SkyQuery_TestTableName, datasetName="MyDB");
print(result)


# In[ ]:

# *******************************************************************************************************
# Files section: