Programing

Hive에서 쿼리를 실행하는 동안 출력과 함께 열 이름을 가져올 수있는 방법이 있습니까?

lottogame 2020. 11. 14. 09:43
반응형

Hive에서 쿼리를 실행하는 동안 출력과 함께 열 이름을 가져올 수있는 방법이 있습니까?


Hive에서는 쿼리 (예 :)를 수행 할 때 select * from employee출력에 열 이름 (예 : RDBMS SQL 에서 얻을 수있는 이름, 나이, 급여)을 얻지 않고 값만 얻습니다.

쿼리를 실행할 때 출력과 함께 열 이름을 표시하는 방법이 있습니까?


HiveQl에서 테이블의 열 이름을 보려면 다음 hive conf 속성을 true로 설정해야합니다.

hive> set hive.cli.print.header=true;

열 이름을 항상보고 싶다면 첫 줄에 위의 설정을 사용하여 $ HOME / .hiverc 파일을 업데이트하십시오.

--Hive는 자동으로 HOME 디렉토리에서 .hiverc라는 파일을 찾고 포함 된 명령을 실행합니다.


출력과 함께 헤더를 인쇄하려면 쿼리를 실행하기 전에 다음 hive conf 속성을 true로 설정해야합니다.

hive> set hive.cli.print.header=true;
hive> select * from table_name;

파일에서 결과를 얻으려면 이와 같은 쿼리를 사용할 수도 있습니다.

hive -e 'set hive.cli.print.header=true;select * from table_name;' > result.xls

여기서 table_name 테이블 이름


위의 모든 답변은 이미 질문에 대한 답변입니다. 그러나 누군가이 속성을 영구적으로 ON으로 설정하려는 경우 다음 속성이 있습니다. hive.cli.print.headerin hive-default.xml또는 hive-site.xml.

기본값은 false입니다. 그 값을 참으로 만들고 저장하십시오. 끝난.


대부분의 솔루션은 정확합니다.

속성 설정이 hive.cli.print.header = true작동합니다.

그러나 cloudera, HDP 또는 기타 배포를 사용하는 경우 이러한 배포가 재설정됩니다. 따라서 Hive 구성에서 이러한 값을 업데이트하고 서비스를 다시 시작하십시오.

이것은 영구적 인 수정입니다. 도움이 되었기를 바랍니다.


쿼리를 실행하기 전에이 속성을 설정하십시오.

hive> set hive.cli.print.header=true;

사용하다 set hive.cli.print.header=true;

hive> set hive.cli.print.header=true;      
hive> select * from tblemployee;
OK
id      name    gender  salary  departmentid
1       tomr    male    40000   1
2       cats    female  30000   2
3       john    male    50000   1
4       james   male    35000   3
5       sara    female  29000   2
6       bens    male    35000   1
7       saman   female  30000   NULL
8       russel  male    40000   2
9       valar   female  30000   1
10      todd    male    95000   NULL
Time taken: 9.892 seconds

1)Permenant solution
change this property in hive-site.xml file under $HIVE_HOME/conf folder
    <property>
    <name>hive.cli.print.header</name>
    <value>true</value>
    <description>Whether to print the names of the columns in query output.
    </description>
    </property>
2)Temporary solution:
go to hive prompt execute this comman
   hive>set hive.cli.print.header=True

참고URL : https://stackoverflow.com/questions/17985836/is-there-any-way-to-get-the-column-name-along-with-the-output-while-execute-any

반응형