DATE 타입 값에 대해서 where.. between을 사용하려면 TO_TIMESTAMP를 사용한다


where service_tag = 'google_plus' and log_time between TO_TIMESTAMP('2017-12-19 10:00:24.000') and TO_TIMESTAMP('2017-12-19 10:05:24.000') order by timestamp 


https://phoenix.apache.org/language/functions.html#to_timestamp



current_time()과 now()의 결과는 동일하다.


> select current_time();

+---------------------------------+

| TIME '2017-12-19 03:05:53.873'  |

+---------------------------------+

| 2017-12-19 03:05:53.873         |

+---------------------------------+

1 row selected (0.006 seconds)


> select now();

+---------------------------------+

| DATE '2017-12-19 03:05:56.345'  |

+---------------------------------+

| 2017-12-19 03:05:56.345         |

+---------------------------------+






1분전, 2분전 결과를 보고 싶다면 다음 결과를 확인한다.


> select now(), now() - (1.0 / (60 * 24));


+---------------------------------+---------------------------------+

| DATE '2017-12-19 03:10:39.428'  | DATE '2017-12-19 03:09:39.429'  |

+---------------------------------+---------------------------------+

| 2017-12-19 03:10:39.428         | 2017-12-19 03:09:39.429         |

+---------------------------------+---------------------------------+

1 row selected (0.005 seconds)



> select now(), now() - (2.0 / (60 * 24));

+---------------------------------+---------------------------------+

| DATE '2017-12-19 03:10:42.772'  | DATE '2017-12-19 03:08:42.772'  |

+---------------------------------+---------------------------------+

| 2017-12-19 03:10:42.772         | 2017-12-19 03:08:42.772         |

+---------------------------------+---------------------------------+










시간과 날짜 함수는 다음과 같이 지원한다.


Time and Date Functions

TO_DATE
TO_TIME
TO_TIMESTAMP
CURRENT_TIME
CONVERT_TZ
TIMEZONE_OFFSET
NOW
YEAR
MONTH
WEEK
DAYOFYEAR
DAYOFMONTH
DAYOFWEEK
HOUR
MINUTE
SECOND



Posted by '김용환'
,

[Phoenix] describe

hbase 2017. 12. 19. 11:49



Phoenix 테이블 정보를 보려면 다음과 같이 느낌표를 먼저 입력하고 describe를 입력한다. 




> !describe <테이블 이름>

+------------+--------------+------------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-------------------+-------------+

| TABLE_CAT  | TABLE_SCHEM  |    TABLE_NAME    | COLUMN_NAME  | DATA_TYPE  | TYPE_NAME  | COLUMN_SIZE  | BUFFER_LENGTH  | DECIMAL_DIGITS  | NUM_PREC_RADIX  | NULLABLE  | REMARKS  | COLUMN_DEF  | SQL_DATA_TYPE  | SQL_DATETIME_SUB  | CHAR_OCTET_ |

+------------+--------------+------------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-------------------+-------------+










모르면 > !help를 입력한다.


!help

!all                Execute the specified SQL against all the current

                    connections

!autocommit         Set autocommit mode on or off

!batch              Start or execute a batch of statements

!brief              Set verbose mode off

!call               Execute a callable statement

!close              Close the current connection to the database

!closeall           Close all current open connections

!columns            List all the columns for the specified table

!commit             Commit the current transaction (if autocommit is off)

!connect            Open a new connection to the database.

!dbinfo             Give metadata information about the database

!describe           Describe a table

!dropall            Drop all tables in the current database

!exportedkeys       List all the exported keys for the specified table

!go                 Select the current connection

!help               Print a summary of command usage

!history            Display the command history

!importedkeys       List all the imported keys for the specified table

!indexes            List all the indexes for the specified table

!isolation          Set the transaction isolation for this connection

!list               List the current connections

!manual             Display the SQLLine manual

!metadata           Obtain metadata information

!nativesql          Show the native SQL for the specified statement

!outputformat       Set the output format for displaying results

                    (table,vertical,csv,tsv,xmlattrs,xmlelements)

!primarykeys        List all the primary keys for the specified table

!procedures         List all the procedures

!properties         Connect to the database specified in the properties file(s)

!quit               Exits the program

!reconnect          Reconnect to the database

!record             Record all output to the specified file

!rehash             Fetch table and column names for command completion

!rollback           Roll back the current transaction (if autocommit is off)

!run                Run a script from the specified file

!save               Save the current variabes and aliases

!scan               Scan for installed JDBC drivers

!script             Start saving a script to a file

!set                Set a sqlline variable


Variable        Value      Description

=============== ========== ================================

Posted by '김용환'
,


아파치 피닉스(Apache Phoenix)에 실시간 로그를 저장해보고 있다.

sqlline에서 로그가 너무 많을 때는 테이블에서 로그가 보이지도 않는다. 


데이터를 보는 뷰가 horizontal, vertical로 되어 있다. 기본 뷰는 horizontal이다. 


로그가 길면 볼 방법이 없다. 그러나 outputformat을 사용하면 유용하다.



> !outputformat vertical 


> select now(), now() - (2.0 / (60 * 24));

DATE '2017-12-19 03:12:39.899'  2017-12-19 03:12:39.899

DATE '2017-12-19 03:10:39.899'  2017-12-19 03:10:39.899






다시 원래 기본 뷰를 사용하려면 다음 커맨드를 실행한다.


> !outputformat table

select now(), now() - (2.0 / (60 * 24));

+---------------------------------+---------------------------------+

| DATE '2017-12-19 03:12:20.209'  | DATE '2017-12-19 03:10:20.209'  |

+---------------------------------+---------------------------------+

| 2017-12-19 03:12:20.209         | 2017-12-19 03:10:20.209         |

+---------------------------------+---------------------------------+




이외 여러 결과 포맷을 사용할 수 있다. 


> !outputformat csv

> select now(), now() - (2.0 / (60 * 24));

'DATE '2017-12-19 05:06:44.272'','DATE '2017-12-19 05:04:44.272''

'2017-12-19 05:06:44.272','2017-12-19 05:04:44.272'




> !outputformat tsv

> select now(), now() - (2.0 / (60 * 24));

'DATE '2017-12-19 05:07:23.258'' 'DATE '2017-12-19 05:05:23.258''

'2017-12-19 05:07:23.258' '2017-12-19 05:05:23.258'



>!outputformat xmlattr

> select now(), now() - (2.0 / (60 * 24));

<resultset>

  <result DATE '2017-12-19 05:09:30.500'="2017-12-19 05:09:30.500" DATE '2017-12-19 05:07:30.500'="2017-12-19 05:07:30.500"/>

</resultset>



> !outputformat xmlelements

> select now(), now() - (2.0 / (60 * 24));

<resultset>

  <result>

    <DATE '2017-12-19 05:09:53.013'>2017-12-19 05:09:53.013</DATE '2017-12-19 05:09:53.013'>

    <DATE '2017-12-19 05:07:53.013'>2017-12-19 05:07:53.013</DATE '2017-12-19 05:07:53.013'>

  </result>

</resultset>

Posted by '김용환'
,



React에서 컴포넌트의 생명 주기를 다룬 깃허브 글이 있어 소개한다.

http://busypeoples.github.io/post/react-component-lifecycle/



초기화를 하면 다음과 같은 순서대로 리액트 함수가 호출된다.




GetDefaultProp  =>  GetInitialState  => ComponentWillMount => Render => ComponentDidMound




state를 변경하면  다음과 같은 순서대로 리액트 함수가 호출된다.





props를 변경하면 다음과 같은 순서대로 리액트 함수가 호출된다.




unmount가 되면 다음 리액트 함수가 호출된다. 




개발해보니 react 컴포넌트가 로딩되기 전, 후에 작업은 componentWillUnmount, componentWillMount를 사용할 때가 가장 많이 사용되는 것 같다. 

Posted by '김용환'
,


fluentd의 filter/record안에서는 예약어가 존재한다.



https://docs.fluentd.org/v0.12/articles/filter_record_transformer



<filter foo.bar>
  @type record_transformer
  <record>
    hostname "#{Socket.gethostname}"
    tag ${tag}
  </record>
</filter>


요청이 다음과 같이 들어오면.. 


{"message":"hello world!"}

hostname과 tag가 추가된다.

{"message":"hello world!", "hostname":"db001.internal.example.com", "tag":"foo.bar"}




중간에 Parameter 내용을 보면.. 


record 디렉티브 하위에 tag_xxx, tag, time, hostname을 사용할 수 있다고 한다.


예를 들어 time을 통해 발생 시간이 넘어온다.






Parameters

<record> directive

Parameters inside <record> directives are considered to be new key-value pairs:

<record>
  NEW_FIELD NEW_VALUE
</record>

For NEW_FIELD and NEW_VALUE, a special syntax ${} allows the user to generate a new field dynamically. Inside the curly braces, the following variables are available:

  • The incoming event’s existing values can be referred by their field names. So, if the record is {"total":100, "count":10}, then record["total"]=100 and record["count"]=10.
  • tag_parts[N] refers to the Nth part of the tag. It works like the usual zero-based array accessor.
  • tag_prefix[N] refers to the first N parts of the tag. It works like the usual zero-based array accessor.
  • tag_suffix[N] refers to the last N parts of the tag. It works like the usual zero-based array accessor.
  • tag refers to the whole tag.
  • time refers to stringanized event time.
  • hostname refers to machine’s hostname. The actual value is result of Socket.gethostname.




'Cloud' 카테고리의 다른 글

[k8s] postgresql 운영 - stateful (펌질)  (0) 2018.01.25
[fluentd]의 fluent-plugin-forest(forest)  (0) 2018.01.22
NIFI의 provenance 의 drop event  (0) 2017.12.12
NIFI 팁  (0) 2017.12.08
[nifi] tail -> cassandra 저장 예제  (0) 2017.12.01
Posted by '김용환'
,



React에서 부모 컴포넌트의 state를 자식 컴포넌트의 state로 이동시킬 수 있는 방법은 다음과 같다.


https://ourcodeworld.com/articles/read/409/how-to-update-parent-state-from-child-component-in-react



class Parent extends React.Component {
    constructor(props) {
        super(props)

        // Bind the this context to the handler function
        this.handler = this.handler.bind(this);

        // Set some state
        this.state = {
            messageShown: false
        };
    }

    // This method will be sent to the child component
    handler() {
        this.setState({
            messageShown: true
        });
    }

    // Render the child component and set the action property with the handler as value
    render() {
        return <Child action={this.handler} />
    }
}




class Child extends React.Component {
    render() {
        return (
            <div>
                {/* The button will execute the handler function set by the parent component */}
                <Button onClick={this.props.action} />
            </div>
        )
    }
}



일반 함수로 리턴할 수 있어서 좋다. 




https://www.quora.com/Why-doesnt-React-automatically-allow-child-components-to-call-setState-of-the-parent-component


  1. class ParentComponent extends React.Component {
  2. onClick() {
  3. const _childValue = this.state.childValue;
  4. this.setState({ childValue: _childValue + 1 });
  5. }
  6. render() {
  7. return (<ChildComponent value={this.state.childVvalue} onClick={this.onClick.bind(this)} />)
  8. }
  9. }
  10. class ChildComponent extends React.Component {
  11. render() {
  12. return (
  13. <span>
  14. <div>My value: {this.props.value} </div>
  15. <button onClick={this.props.onClick}>Increment</button>
  16. </span>
  17. )
  18. }
  19. }



Posted by '김용환'
,



일리노이주 주립 대학의 coursera CS master 강의가 떠서 확인해보았다. 





https://cs.illinois.edu/admissions/graduate/degree-program-options



학부 성적은 3.2가 되어야 한다





https://cs.illinois.edu/admissions/graduate/applications-process-requirements


등록 절차

- 추천서

- 공부 목적 

- 이력서


등등




https://cs.illinois.edu/additional-required-application-materials-international-students



A passing score on the TOEFL iBT (spoken portion of the exam only) is 24/30. And, a passing score on the IELTS (on the spoken portion of the exam only) is 8.



역시 영어를 잘해야 하나 보다.. 


Posted by '김용환'
,




Learning Apache Cassandra 2/e 번역을 2017년 10월에 마무리했고 출간을 기다리는 중이다. 


이 책은 1/e을 기준으로 cassandra 3.0 기준으로 정리한 책이다. 


워낙 내용이 좋고 SNS 기반 예제라서 카산드라의 장점(또는 DB 스키마)을 잘 살린 케이스이다.. 



Posted by '김용환'
,



올해 초에 번역을 완료했던 Shell Programming in Unix, Linux and OS X: The Fourth Edition of Unix Shell Programming (4th Edition) (Developer's Library) 4th Edition 책이 에이콘출판사에서 "유닉스, 리눅스, OS X 환경에서 사용할 수 있는 셸 스크립트 프로그래밍 입문 4/e"로 출간되었다.


https://www.amazon.com/Shell-Programming-Unix-Linux-Developers/dp/0134496000


http://www.acornpub.co.kr/book/shell-unix-linux-osx-4






이 책을 보면서 원리를 알기 보다 바로 사용하는 것에 급급했던 내 자신을 반성했다. 


서버를 하면 반드시 알아야 했던 셸 스크립트를 POSIX 기준으로 설명한 책으로 기초가 튼실한 책이다. 


서버 개발이나 셸 스크립트를 진행하는 개발자에게 좋을것 같다. 





옮긴이의 말

리눅스는 무료 운영체제지만 안정성이 좋아 많은 회사에서 서버 환경으로 사용되고 있다. 이제 리눅스를 쓰지 않는 IT 회사는 찾아보기 어렵다. 또한 개발과 운영을 동시에 진행해야 하는 데브옵스라면 리눅스는 필수로 알아야 할 운영체제가 되고 있다. 프로그래밍 언어를 사용해 개발된 애플리케이션을 리눅스에서 실행하고 관리하기 위해서는 간단하게 리눅스에 대한 기본 지식을 습득하고 셸 프로그래밍을 기본적으로 해야 한다. 게다가 최근 많은 IT 회사에서 개발자 직군에게 유닉스 계열의 OS X가 설치된 맥북을 지급하고 있다(또한 디자이너 직군과 개발자 직군뿐 아니라, 일반 기획자와 사무직 직군에게도 지급되고 있어서 맥의 OS X를 알아야 하는 상황이다). 따라서 서버 환경에서만 작업할 수 있는 환경이 로컬 환경에서도 동일하게 구축할 수 있게 됐다. 데브옵스, 클라우드, 도커 기술이 보편화하면서 특히 셸 프로그래밍은 기본적으로 알아야 할 내용이 됐다. 이제는 피해갈 수 없다. 선택이 아닌 필수 지식에 가까워서 부담스러울 수 있겠지만 독자 여러분들이 즐겁게 배우고 리눅스를 깊이 알아가면 좋겠다. 이 책은 셸 프로그래밍을 배우길 원하는 개발자, 시스템 엔지니어, 일반인에게도 도움이 된다. 게다가 이 책의 예제와 설명은 유닉스, 리눅스, OS X 모두를 지원하는 POSIX 표준 셸을 기반으로 한다. 따라서 이 책에서 배운 기술을 대부분의 유닉스 계열 운영체제에서 사용할 수 있다. 많은 유틸리티와 셸 프로그래밍 기술 등 현업에서 적용할 만한 내용이 이 책에 가득하다. 훌륭한 책인 만큼 여러분에게 추천하고 싶다. 나는 리눅스를 평생 친구로 생각해왔다. 특히 윈도우보다 리눅스를 좋아한다. 아마도 대학생일 때, 학교에 있는 유닉스 터미널에서 MUD 게임을 하면서 점점 유닉스 운영체제에 관심을 갖게 된 것 같다. 그리고 조금씩 리눅스 유틸리티와 셸 프로그래밍에 대해 배운 내용을 블로그에 정리하기 시작했다. 이전 직장에서는 리눅스를 조금 안다는 이유로 커널 디바이스 프로그래밍을 해볼 좋은 기회를 얻었다. 리눅스 유틸리티를 알고 리눅스의 동작 방식을 이해하고 때로는 커널 내부 구조를 공부하며 리눅스 지식을 넓히는 것이 좋았다. 아무래도 리눅스 운영체제가 내 말을 알아듣고 내가 원하는 동작을 하는 것이 좋았기 때문이리라. 이 책을 읽는 분들도 내가 느꼈던 희열을 함께 느끼면 좋을 것 같다. 파이팅!





--

(추가)


현재(2018년) 모 아카데미에서 교재로 쓰인다고 한다..


Posted by '김용환'
,



react에서 props와 state를 마구 썼더니. 조금씩 보인다. 


비슷하긴 한데. 중요한 차이가 있다. 



전역 상수(immutable)와 같은 개념은 props를


일반 변수(mutable)과 같은 개념은 state를 사용한다. 





실제 해보니.. 



초기값은 props로 저장하고 defaultValue에 사용하고,


변수 값 (input, datetime 등의 value)를 얻기 위해 state를 사용하니 유연하다. 





자세한 내용은 아래를 참조한다. 


https://velopert.com/921



Posted by '김용환'
,