복붙노트

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

HADOOP

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

Hive에서 검색어 (예 : select * from employee)를 수행 할 때 우리는 출력에 열 이름 (예 : RDBMS SQL에 포함 된 이름, 나이, 급여)을 얻지 못하고 값만 가져옵니다.

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

해결법

  1. ==============================

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

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

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

    열 이름을 항상보고 싶다면 $ HOME / .hiverc 파일을 첫 번째 행의 위 설정으로 업데이트하십시오.

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

  2. ==============================

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

    출력과 함께 헤더를 인쇄하려면 쿼리를 실행하기 전에 다음 하이브 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
    

    where table_name 당신의 테이블 이름

  3. ==============================

    3.위의 모든 대답은 이미 질문에 대한 답변입니다. 그러나 누군가이 속성을 영구적으로 사용하기를 원한다면 hive-default.xml 또는 hive-site.xml에 hive.cli.print.header 속성이 있습니다.

    위의 모든 대답은 이미 질문에 대한 답변입니다. 그러나 누군가이 속성을 영구적으로 사용하기를 원한다면 hive-default.xml 또는 hive-site.xml에 hive.cli.print.header 속성이 있습니다.

    기본값은 false입니다. 그 가치를 사실로 만들고 저장하라. 끝난.

  4. ==============================

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

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

    hive.cli.print.header = true 속성을 설정하면됩니다.

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

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

  5. ==============================

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

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

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

    6.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
    
  7. ==============================

    7.

    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
    
  8. from https://stackoverflow.com/questions/17985836/is-there-any-way-to-get-the-column-name-along-with-the-output-while-execute-any by cc-by-sa and MIT license