Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def downloadFile(username, password, tableName_, databaseName_, filename):
    login(username, password)
    print("Authentication complete, downloading table")
    table = SkyQuery.getTable(tableName=tableName_, datasetName=databaseName_)
    print("Download complete, writing to CSV")
    table.to_csv(filename)
    print("Table contents have been written to file " + filename)
    print("Table info: \n", table)
Ejemplo n.º 3
0
        'There are already tables in your database under that name, removing them before doing new query...'
    )
    #CLEAN UP: delete table from myDB
    SkyQuery.dropTable(tableName=tname, datasetName='myDB')

#long asynchronous job
print(
    'submitting SQL job to SciServer... could take some time depending on query length and SciServer load...'
)
jobID = CasJobs.submitJob(query + "into myDB." + tname, "dr14")
CasJobs.waitForJob(jobID, verbose=True)

try:
    #Download table from MYDB into Pandas dataframe. additional parms: , top=10
    print('Attempting to download table...')
    data_table = SkyQuery.getTable(tableName=tname, datasetName='MyDB')
    print('Done! Table shape is: ' + str(data_table.shape))
    #save df to disk in case of super long queries:
    filename = 'test_query_table_1000'
    print('Saving tables to disk as: ' + filename)
    save_obj(data_table, filename)
except:
    print(
        'ERROR, No data found in your SciServer database, query may not have completed, check your SQL syntax?'
    )
    #see tables in MyDB
    tables = SkyQuery.listDatasetTables('MyDB')
    print('tables found: ', tables)

#CLEAN UP: delete table from myDB
SkyQuery.dropTable(tableName=tname, datasetName='MyDB')
SkyQuery_TestTableCSV = u"Column1,Column2\n4.5,5.5\n"


# In[ ]:

#uploading the csv table:

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


# In[ ]:

#downloading table:

table = SkyQuery.getTable(tableName=SkyQuery_TestTableName, datasetName="MyDB", top=10)
print(table)


# In[ ]:

#list tables inside dataset

tables = SkyQuery.listDatasetTables("MyDB")
print(tables)


# In[ ]:

#get dataset table info: