Hive - get_json_object 호출시 에러 


hive에서 hive udf의 json을 사용하려 할 때(get_json_object를 사용, ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'를 사용) 다음 에러가 발생한다. 


Error while compiling statement: FAILED: RuntimeException MetaException(message:java.lang.ClassNotFoundException Class org.openx.data.jsonserde.JsonSerDe not found)
class org.apache.hive.service.cli.HiveSQLException



에러가 발생하지 않고 정상적으로 실행하려면,다음과 같이 실행하면 get_json_object가 실행된다.

$ wget http://www.congiu.net/hive-json-serde/1.3.7/cdh5/json-serde-1.3.7-jar-with-dependencies.jar
$ hive
hive> add jar /위치/json-serde-1.3.7-jar-with-dependencies.jar


세션이 실행될 때마다 동작시키려면 .hiverc를 수정한다.


$ vi ~/.hiverc

..

add jar /위치/json-serde-1.3.7-jar-with-dependencies.jar











Posted by '김용환'
,





hive 쿼리를 실행 중에 예약어를 쓰면 에러가 발생할 수 있다. 



FAILED: ParseException line 1:85 Failed to recognize predicate 'to'. Failed rule: 'identifier' in table or column identifier



이럴 때는 두 가지 방법으로 문제를 해결할 수 있다. 


1번째 방법이다. 


SET hive.support.sql11.reserved.keywords=false;

select * from src.google_plus_log where date_id='2037-02-22' and to='365600561231231123121212'


2번째 방법은 back quote를 사용한다.


select * from src.google_plus_log where date_id='2037-02-22' and `to`='365600561231231123121212'


Posted by '김용환'
,



top 커맨드의 메모리 관련 내용(VIRT, RES, SHR, %MEM)를 설명한다.


이를 설명하기 좋은 프로세스는 mongodb인 듯 해서 그 부분만 정리했다. 


실제 메모리를 보기 위해 free 커맨드를 실행하면 cached 메모리 때문에 마치 used 메모리가 상승했다.



$ free

                     total       used              free         shared    buffers     cached

Mem:      16289804   15621900     667904        188     148776    7787380

-/+ buffers/cache:     7685744      8604060

Swap:     10485756          0            10485756




top으로 보면 대략 전체 메모리는 16G이고 사용 중인 메모리는 15G이다. 

VIRT는 12.8G, RES는 6.7G, SHR은 6512로 나타난다. 


$ top

Mem:  16289804k total, 15621300k used,   668504k free,   148776k buffers

Swap: 10485756k total,        0k used, 10485756k free,  7787328k cached


PID USER      PR   NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

17075 www    20   0 12.8g 6.7g 6512 S  0.7        43.2   4321:34 mongod




이것만 보고 정말 물리 메모리를 더 꽂아야 하냐고 묻길래. 아니라고 답변해 주었다. 



top 커맨드의 중요 메모리 설정을 살펴본다.


* VIRT는 프로세스의 가상 크기를 의미한다. 실제로 사용하고 있는 메모리의 총합을 의미한다. VIRT는 
 디스크의 파일을 읽으면서 사용했던 메모리도 포함될 수 있다. VIRT는 프로그램이 현재 얼마나 많은 메모리를 접근할 수 있는지 나타낸다. (즉 물리 메모리의 사용한 공간을 의미하지 않는다.) 


* RES는 실제 물리 메모리를 얼마나 쓰고 있는지 나타낸다. 따라서 VIRT보다는 작은 값을 보여준다.
%MEM의 내용에 연관된다.


* SHR은 VIRT 메모리 중 공유 메모리를 보여준다.



참고로 리눅스에서 물리 메모리 페이지 영역을 볼 수 있다. 
특정 PID의 세그먼트(segment)에 할당된 물리 메모리 페이지를 보여준다.

$ cat /proc/${PID}/smaps
..
7f8248fb2000-7f8249223000 rw-p 00000000 00:00 0
Size:               2500 kB
Rss:                1492 kB
Pss:                1492 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:      1492 kB
Referenced:         1488 kB
Anonymous:          1492 kB
AnonHugePages:         0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
7f8249223000-7f8249472000 ---p 00000000 00:00 0
Size:               2364 kB
Rss:                   0 kB
Pss:                   0 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            0 kB
Anonymous:             0 kB
AnonHugePages:         0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
7f8249472000-7f824948c000 r-xp 00000000 08:02 1326344                    /usr/java/jdk1.8.0_25/jre/lib/amd64/libzip.so
Size:                104 kB
Rss:                  84 kB
Pss:                  43 kB
Shared_Clean:         60 kB
Shared_Dirty:          0 kB
Private_Clean:        24 kB
Private_Dirty:         0 kB
Referenced:           84 kB
Anonymous:             0 kB
AnonHugePages:         0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
...


이 정보의 간략화된 버전이다. 

$ cat /proc/${PID}/maps

7f8248fb2000-7f8249223000 rw-p 00000000 00:00 0
7f8249223000-7f8249472000 ---p 00000000 00:00 0
7f8249472000-7f824948c000 r-xp 00000000 08:02 1326344                    /usr/java/jdk1.8.0_25/jre/lib/amd64/libzip.so





더 깊이 보면 보면 재미있어야 할 내용들 레퍼런스 

1. https://en.wikipedia.org/wiki/Virtual_memory의 address space swapping


2. https://www.youtube.com/watch?v=twQKAoq2OPE


3. https://web.eecs.umich.edu/~pmchen/eecs482/handouts/memory.pdf






Posted by '김용환'
,



hbase 클라이언트 사용 할 때, hbase 서버와의 버전을 반드시 확인해야 프로토콜 이슈가 없다.


하지만, cassandra는 최상위 버전인 3.1.4 버전의 클라이언트 라이브러를 사용해도 일부 하위 버전까지 하위 호환성을 유지한다..





https://github.com/datastax/java-driver


The Java client driver 3.1.4 (branch 3.1) is compatible with Apache Cassandra 1.2, 2.0, 2.1, 2.2 and 3.0 (see this pagefor the most up-to-date compatibility information).




http://datastax.github.io/java-driver/manual/native_protocol



Native protocol

The native protocol defines the format of the binary messages exchanged between the driver and Cassandra over TCP. As a driver user, you don’t need to know the fine details (although the protocol spec is in the Cassandra codebase if you’re curious); the most visible aspect is that some features are only available with specific protocol versions.

Compatibility matrix

By default, the protocol version is negotiated between the driver and Cassandra when the first connection is established. Both sides are backward-compatible with older versions:


 Cassandra: 1.2.x
(DSE 3.2)
2.0.x
(DSE 4.0 to 4.6)
2.1.x
(DSE 4.7)
2.2.x3.0.x
Driver: 1.0.xv1v1v1v1Unsupported (1)
2.0.x to 2.1.1v1v2v2v2Unsupported (1)
2.1.2 to 2.1.xv1v2v3v3Unsupported (2)
3.xv1v2v3v4v4

(1) Cassandra 3.0 does not support protocol versions v1 and v2

(2) There is a matching protocol version (v3), but the driver 2.1.x can’t read the new system table format of Cassandra 3.0

For example, if you use version 2.1.5 of the driver to connect to Cassandra 2.0.9, the maximum version you can use (and the one you’ll get by default) is protocol v2 (third row, second column). If you use the same version to connect to Cassandra 2.1.4, you can use protocol v3.




netty 버전과 이슈가 있을 수 있으니.아래 내용도 참고한다. 


https://github.com/datastax/java-driver/tree/3.1.x/manual/shaded_jar







참고로 cassandra 2.1에서 3.1로 올리는 테스트해보니 바로 되지 않는 부분이 있다.


LocalDate의 getTime 메소드 같은 경우는 아예 사라져 있다.


long startDate = row.getDate("date1").getTime();




다음과 같은 에러가 발생했다.


 (188): Codec not found for requested operation: [timestamp <-> com.datastax.driver.core.LocalDate]

com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [timestamp <-> com.datastax.driver.core.LocalDate]

        at com.datastax.driver.core.CodecRegistry.notFound(CodecRegistry.java:679) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.createCodec(CodecRegistry.java:526) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.findCodec(CodecRegistry.java:506) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.access$200(CodecRegistry.java:140) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:211) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry$TypeCodecCacheLoader.load(CodecRegistry.java:208) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache.get(LocalCache.java:3934) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938) ~[story-app.jar:na]

        at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.lookupCodec(CodecRegistry.java:480) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:448) ~[story-app.jar:na]

        at com.datastax.driver.core.CodecRegistry.codecFor(CodecRegistry.java:430) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableByIndexData.codecFor(AbstractGettableByIndexData.java:69) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableByIndexData.getDate(AbstractGettableByIndexData.java:174) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableData.getDate(AbstractGettableData.java:26) ~[story-app.jar:na]

        at com.datastax.driver.core.AbstractGettableData.getDate(AbstractGettableData.java:111) ~[story-app.jar:na]




다음 코드로 변경하면 잘 동작한다. 

row.getTimestamp("date1").getTime();



좋은 자료

https://groups.google.com/a/lists.datastax.com/forum/#!topic/java-driver-user/pAoLlEzmGWA

https://datastax-oss.atlassian.net/browse/JAVA-1176




maven dependency 3.1과 2.1 비교 



cassandra 3.1

[INFO] +- com.datastax.cassandra:cassandra-driver-core:jar:3.1.3:compile

[INFO] |  +- io.netty:netty-handler:jar:4.0.37.Final:compile

[INFO] |  |  +- io.netty:netty-buffer:jar:4.0.37.Final:compile

[INFO] |  |  |  \- io.netty:netty-common:jar:4.0.37.Final:compile

[INFO] |  |  +- io.netty:netty-transport:jar:4.0.37.Final:compile

[INFO] |  |  |  \- (io.netty:netty-buffer:jar:4.0.37.Final:compile)

[INFO] |  |  \- io.netty:netty-codec:jar:4.0.37.Final:compile

[INFO] |  |     \- (io.netty:netty-transport:jar:4.0.37.Final:compile)

[INFO] |  +- (com.google.guava:guava:jar:16.0.1:compile)

[INFO] |  +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile

[INFO] |  |  \- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for conflict with 1.7.6)

[INFO] |  +- com.github.jnr:jnr-ffi:jar:2.0.7:compile

[INFO] |  |  +- com.github.jnr:jffi:jar:1.2.10:compile

[INFO] |  |  +- com.github.jnr:jffi:jar:native:1.2.10:runtime

[INFO] |  |  +- (org.ow2.asm:asm:jar:5.0.3:compile - omitted for conflict with 4.1)

[INFO] |  |  +- (org.ow2.asm:asm-commons:jar:5.0.3:compile - omitted for conflict with 4.1)

[INFO] |  |  +- org.ow2.asm:asm-analysis:jar:5.0.3:compile

[INFO] |  |  |  \- (org.ow2.asm:asm-tree:jar:5.0.3:compile)

[INFO] |  |  +- org.ow2.asm:asm-tree:jar:5.0.3:compile

[INFO] |  |  |  \- (org.ow2.asm:asm:jar:5.0.3:compile - omitted for conflict with 4.1)

[INFO] |  |  +- org.ow2.asm:asm-util:jar:5.0.3:compile

[INFO] |  |  |  \- (org.ow2.asm:asm-tree:jar:5.0.3:compile)

[INFO] |  |  \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile

[INFO] |  \- com.github.jnr:jnr-posix:jar:3.0.27:compile

[INFO] |     +- (com.github.jnr:jnr-ffi:jar:2.0.7:compile)

[INFO] |     \- com.github.jnr:jnr-constants:jar:0.9.0:compile



cassandra 2.1



[INFO] +- com.datastax.cassandra:cassandra-driver-core:jar:2.1.9:compile

[INFO] |  +- io.netty:netty-handler:jar:4.0.27.Final:compile

[INFO] |  |  +- io.netty:netty-buffer:jar:4.0.27.Final:compile

[INFO] |  |  |  \- io.netty:netty-common:jar:4.0.27.Final:compile

[INFO] |  |  +- io.netty:netty-transport:jar:4.0.27.Final:compile

[INFO] |  |  |  \- (io.netty:netty-buffer:jar:4.0.27.Final:compile)

[INFO] |  |  \- io.netty:netty-codec:jar:4.0.27.Final:compile

[INFO] |  |     \- (io.netty:netty-transport:jar:4.0.27.Final:compile)

[INFO] |  +- (com.google.guava:guava:jar:14.0.1:compile - omitted for conflict with 16.0.1)

[INFO] |  \- com.codahale.metrics:metrics-core:jar:3.0.2:compile

[INFO] |     \- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for conflict with 1.7.6)


Posted by '김용환'
,



"마침표(.)" 커맨드는 쉘이 지정 파일을 읽고 실행할 수 있게 한다. file은 실행 가능한 필요는 없고, 읽을 수 있으면 된다. 또한 쉘은 PATH 변수를 사용하여 file을 찾는다. 서브쉘에 전달되지 않는다.



$ cat varx
AAA=a
BBB=b

$ . varx

$ echo $AAA
a

$ echo $BBB
b






Posted by '김용환'
,

널 커맨드 - :

unix and linux 2017. 2. 23. 08:46




: 커맨드는 본질적으로 널(null) 커맨드이다. 커맨드가 있어야 하는 요구 사항을 충족시키는 데 자주 사용된다.



 if [ $(id -u) != "0" ]; then : ; else echo "superuser"; fi



Posted by '김용환'
,