2017-06-22 8 views
0

Im Anschluss an dem Daten-Set I in einer Hive Tabelle temp_stat genannt gedrückt:Tabellendefinition Probleme in Apache HIVE

COUNTRY CITY     TEMP 
---------- -------------------- ----- 
US   Arizona    51.7 
US   California   56.7 
US   Bullhead City  51.1 
India  Jaisalmer   42.4 
Libya  Aziziya    57.8 
Iran  Lut Desert   70.7 
India  Banda    42.4 

Als ich versuchte, Daten zu sehen, obwohl die Befehl wählen, ich dann holen sie sich die folgenden Daten-Set:

US,Arizona,51.7   NULL NULL 
US,California,56.7  NULL NULL 
US,Bullhead City,51.1 NULL NULL 
India,Jaisalmer,42.4 NULL NULL 
Libya,Aziziya,57.8  NULL NULL 
Iran,Lut Desert,70.7 NULL NULL 
India,Banda,42.4  NULL NULL 

Next I Gruppe wollte diese Aufzeichnung auf Land erniedrigte und für jede countr maximale Temperatur holen y zusammen mit dem Namen der Stadt, so lief ich die folgende Abfrage:

select country,city,temp 
from (
select country,city,temp, 
    row_number() over (partition by country order by temp desc) as part 
from temp_stat 
) a 
where part = 1 
order by country, city; 

Sobald ich die obige Abfrage in hive Shell ausführen, erhalte ich folgendes Ergebnis:

US,Arizona,51.7   NULL NULL 
US,California,56.7  NULL NULL 
US,Bullhead City,51.1 NULL NULL 
India,Jaisalmer,42.4 NULL NULL 
Libya,Aziziya,57.8  NULL NULL 
Iran,Lut Desert,70.7 NULL NULL 
India,Banda,42.4  NULL NULL 

Auch wenn ich laufe die innere Abfrage zu generieren row_number dann bekomme ich auch ähnliche Zeilennummern für alle Datensätze. (Something like this :)

India,Banda,42.4  NULL NULL 1 
India,Jaisalmer,42.4 NULL NULL 1 
Iran,Lut Desert,70.7 NULL NULL 1 
Libya,Aziziya,57.8  NULL NULL 1 
US,Arizona,51.7   NULL NULL 1 
US,Bullhead City,51.1 NULL NULL 1 
US,California,56.7  NULL NULL 1 
enter code here 

Ich habe auch versucht DENSE_RANK() und Rang(). Keine neuen Ergebnisse. Gibt es ein Problem mit der Tabellendefinition oder was?

Alle Hilfe wäre willkommen!

Antwort

1

Felder beendet ''


Ihre Tabellendefinition so etwas sein sollte:

create external table temp_stat 
(
    country  string 
    ,city  string   
    ,temp  decimal(11,1) 
) 
    row format delimited 
    fields terminated by ',' 
; 

select * from temp_stat; 

+---------+---------------+------+ 
| country |  city  | temp | 
+---------+---------------+------+ 
| US  | Arizona  | 51.7 | 
| US  | California | 56.7 | 
| US  | Bullhead City | 51.1 | 
| India | Jaisalmer  | 42.4 | 
| Libya | Aziziya  | 57.8 | 
| Iran | Lut Desert | 70.7 | 
| India | Banda   | 42.4 | 
+---------+---------------+------+ 
+0

Aus diesem Grund gab meine Abfrage nicht die richtige Ausgabe? – hashir

+0

Ja. Ihre Tabelle ist nicht korrekt definiert. Die gesamte Zeile wird der ersten Spalte zugeordnet und alle anderen Spalten enthalten Nullwerte. –

+0

Danke Kumpel! Der Tisch war wirklich das Problem. Ich folgte dir Methode und lud die Daten ebenfalls und meine Abfrage lief glatt. Es gibt jedoch dieses eine Problem. Wenn ich die folgende Abfrage ausführen: wählen Sie Land, Stadt, Temp, Rang() über (Partition nach Länderreihenfolge von Temp Desc) Rang von Temp_stat; – hashir

Verwandte Themen