2017-07-07 1 views
3

Ich versuche, eine Funktion zum Aktualisieren von Daten aus einer in HBase gespeicherten Tabelle zu schreiben. Ich habe eine Funktion, die aufgerufen wird, um sie zu aktualisieren, und ich habe einen ziemlich guten Start, aber ich bin ein wenig verloren am Ende des Abschlusses. Ich kann einzelne Zeilen basierend auf einer anderen Zeichenfolge aktualisieren, aber wenn ich die Protokollierungszeitpunkte vergleiche, kann ich nicht herausfinden, wie das geht, da es keine festgelegten Protokollierungszeiten gibt. Ich speichere alle Werte aus der Tabelle in ein Wörterbuch. Hier ist mein Code:Aktualisieren von HBase-Daten mit HappyBase

def updateHBase(row): 

dict = row.asDict() #create a dictionary from Row 

columns = dict.keys() 
    for col in columns: #creates the colfamily:colname for happybase format 
     dict["DriveInfo:" +col] = dict.pop(col) #adds data into rows 

del dict[DriveInfo:serialnumb] #removes the row key that HBase uses, serialnum 

x = table.row(row.serialnum) 

if (len(x) == 0) #length of row is zero, row key does not exist 
    table.put(row.serialnum, dict) #add new row is row key does not exist 

else #check for health 
    if (dict['health'].lower() != 'healthy') #if the row isnt healthy... next steps 

     if (dict['health'].lower() != 'archived' and x['health'] == 'archived' and dict['logtime'] < x['logtime']) #update a row with a health status of archived 
      table.put(row.serialnum, dict) 

     else #if the row that is being replaced isn't archived, just replace the row 
      table.put(row.serialnum, dict) 
     return 

    elif (dict['logtime'] > x['logtime'] and dict['health'].lower() == 'healthy') # new log time > old log time and health is healthy, replace the row with new data 
     table.put(row.serialnum, dict) 

    else 
     return 

EDIT: In allen meinen if-Anweisungen sollte ... dict['health'] ... sein x['health']?

Antwort

0

es heraus ...

def updateHBase(row): 

dict = row.asDict() #create a dictionary from Row 

columns = dict.keys() 
    for col in columns: #creates the colfamily:colname for happybase format 
     dict["DriveInfo:" +col] = dict.pop(col) #adds data into rows 

del dict[DriveInfo:serialnumb] #removes the row key that HBase uses, serialnum 

x = table.row(row.serialnum) 

if (len(x) == 0) #length of row is zero, row key does not exist 
    table.put(row.serialnum, dict) #add new row is row key does not exist 

else #check for health 
    if (x['health'].lower() != 'healthy') #if the row isnt healthy... next steps 

     if (x['health'].lower() != 'archived' and x['health'] == 'archived') #update a row with a health status of archived 
      table.put(row.serialnum, dict) 

     else #if the row that is being replaced isn't archived, just replace the row 
      table.put(row.serialnum, dict) 
     return 

    elif (x['logtime'] > row.logtime and x['health'].lower() == 'healthy') # new log time > old log time and health is healthy, replace the row with new data 
     table.put(row.serialnum, dict) 

    else 
     return 
Verwandte Themen