<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Filter a Phoenix Timestamp Column in SparkSQL (Java) in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Filter-a-Phoenix-Timestamp-Column-in-SparkSQL-Java/m-p/235896#M84885</link>
    <description>&lt;P&gt;I have a Phoenix Table, that I can access via SparkSQL (with Phoenix Spark Plugin). The table has also a Timestamp column. &lt;/P&gt;&lt;P&gt;I have to filter this Timestamp column by a user input, like 2018-11-14 01:02:03. So I want to filter my Dataset (that represents the read Phoenix table) with the where / filter methods.&lt;/P&gt;&lt;P&gt;My actual Java code looks the following:&lt;/P&gt;&lt;PRE&gt;Timestamp t1 = new Timestamp(sdf.parse(dateFrom).getTime());
Timestamp t2 = new Timestamp(sdf.parse(dateTo).getTime());
		
Column c1 = new Column("TABLE_TS_COL").geq(t1);
Column c2 = new Column("TABLE_TS_COL").leq(t2);
		
Dataset&amp;lt;Row&amp;gt; dsResult = sqlContext.read()
  .format("org.apache.phoenix.spark")
  .option("table", tableName)
  .option("zkUrl", hbaseUrl).load()
			
  .where("OTHER_COLUMN = " + inputId) // This works
  .where(c1)  // Problem!
  .where(c2)  // Problem!
&lt;/PRE&gt;&lt;P&gt;But this leads to follwoing exception:&lt;/P&gt;&lt;PRE&gt;java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: org.apache.phoenix.exception.PhoenixParserException: ERROR 604 (42P00): Syntax error. Mismatched input. Expecting "RPAREN", got "06" at line 1, column 474.&lt;/PRE&gt;&lt;P&gt;My Spark History UI shows the following select statement:&lt;/P&gt;&lt;PRE&gt;...
18/11/14 08:54:58 INFO PhoenixInputFormat: Select Statement: SELECT "OTHER_COLUMN", "TABLE_TS_COL" FROM HBASE_TEST3 WHERE ( "OTHER_COLUMN" = 0 AND "OTHER_COLUMN" IS NOT NULL AND "TABLE_TS_COL" IS NOT NULL AND "TABLE_TS_COL" &amp;gt;= 2018-09-24 06:49:01.0 AND "TABLE_TS_COL" &amp;lt;= 2018-09-24 06:49:01.0)
&lt;/PRE&gt;&lt;P&gt;For me it looks like the quotation marks are missing for the timestamp values (not sure about that)?&lt;/P&gt;&lt;P&gt;How can I filter a Timestamp column by a user input in Java and SparkSQL?&lt;/P&gt;</description>
    <pubDate>Wed, 14 Nov 2018 16:10:49 GMT</pubDate>
    <dc:creator>dmueller1607</dc:creator>
    <dc:date>2018-11-14T16:10:49Z</dc:date>
    <item>
      <title>Filter a Phoenix Timestamp Column in SparkSQL (Java)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Filter-a-Phoenix-Timestamp-Column-in-SparkSQL-Java/m-p/235896#M84885</link>
      <description>&lt;P&gt;I have a Phoenix Table, that I can access via SparkSQL (with Phoenix Spark Plugin). The table has also a Timestamp column. &lt;/P&gt;&lt;P&gt;I have to filter this Timestamp column by a user input, like 2018-11-14 01:02:03. So I want to filter my Dataset (that represents the read Phoenix table) with the where / filter methods.&lt;/P&gt;&lt;P&gt;My actual Java code looks the following:&lt;/P&gt;&lt;PRE&gt;Timestamp t1 = new Timestamp(sdf.parse(dateFrom).getTime());
Timestamp t2 = new Timestamp(sdf.parse(dateTo).getTime());
		
Column c1 = new Column("TABLE_TS_COL").geq(t1);
Column c2 = new Column("TABLE_TS_COL").leq(t2);
		
Dataset&amp;lt;Row&amp;gt; dsResult = sqlContext.read()
  .format("org.apache.phoenix.spark")
  .option("table", tableName)
  .option("zkUrl", hbaseUrl).load()
			
  .where("OTHER_COLUMN = " + inputId) // This works
  .where(c1)  // Problem!
  .where(c2)  // Problem!
&lt;/PRE&gt;&lt;P&gt;But this leads to follwoing exception:&lt;/P&gt;&lt;PRE&gt;java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: org.apache.phoenix.exception.PhoenixParserException: ERROR 604 (42P00): Syntax error. Mismatched input. Expecting "RPAREN", got "06" at line 1, column 474.&lt;/PRE&gt;&lt;P&gt;My Spark History UI shows the following select statement:&lt;/P&gt;&lt;PRE&gt;...
18/11/14 08:54:58 INFO PhoenixInputFormat: Select Statement: SELECT "OTHER_COLUMN", "TABLE_TS_COL" FROM HBASE_TEST3 WHERE ( "OTHER_COLUMN" = 0 AND "OTHER_COLUMN" IS NOT NULL AND "TABLE_TS_COL" IS NOT NULL AND "TABLE_TS_COL" &amp;gt;= 2018-09-24 06:49:01.0 AND "TABLE_TS_COL" &amp;lt;= 2018-09-24 06:49:01.0)
&lt;/PRE&gt;&lt;P&gt;For me it looks like the quotation marks are missing for the timestamp values (not sure about that)?&lt;/P&gt;&lt;P&gt;How can I filter a Timestamp column by a user input in Java and SparkSQL?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 16:10:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Filter-a-Phoenix-Timestamp-Column-in-SparkSQL-Java/m-p/235896#M84885</guid>
      <dc:creator>dmueller1607</dc:creator>
      <dc:date>2018-11-14T16:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filter a Phoenix Timestamp Column in SparkSQL (Java)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Filter-a-Phoenix-Timestamp-Column-in-SparkSQL-Java/m-p/235897#M84886</link>
      <description>&lt;P&gt;I found the following Java based solution for me: Using the Dataset.filter method with FilterFunction: &lt;A href="https://spark.apache.org/docs/2.3.0/api/java/index.html?org/apache/spark/sql/Dataset.html" target="_blank"&gt;https://spark.apache.org/docs/2.3.0/api/java/index.html?org/apache/spark/sql/Dataset.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;So, my code now looks like this:&lt;/P&gt;&lt;PRE&gt;Dataset&amp;lt;Row&amp;gt; dsResult = sqlC.read()
  .format("org.apache.phoenix.spark")
  .option("table", tableName)
  .option("zkUrl", hbaseUrl).load()

  .where("OTHER_COLUMN = " + inputId)
  .filter(row -&amp;gt; {
	long readTime = row.getTimestamp(row.fieldIndex("TABLE_TS_COL")).getTime();		
	long tsFrom = new Timestamp(sdf.parse(dateFrom).getTime()).getTime();
	long tsTo = new Timestamp(sdf.parse(dateTo).getTime()).getTime();
					
	return readTime &amp;gt;= tsFrom &amp;amp;&amp;amp; readTime &amp;lt;= tsTo;
  });
&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Nov 2018 18:45:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Filter-a-Phoenix-Timestamp-Column-in-SparkSQL-Java/m-p/235897#M84886</guid>
      <dc:creator>dmueller1607</dc:creator>
      <dc:date>2018-11-14T18:45:31Z</dc:date>
    </item>
  </channel>
</rss>

