phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twdsilva <...@git.apache.org>
Subject [GitHub] phoenix pull request: PHOENIX-1661 Implement built-in functions fo...
Date Fri, 24 Jul 2015 01:08:57 GMT
Github user twdsilva commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/93#discussion_r35388362
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/JsonArrayLengthFunctionIT.java
---
    @@ -0,0 +1,114 @@
    +/**
    + * 
    + */
    +package org.apache.phoenix.end2end;
    +
    +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +
    +import java.sql.Connection;
    +import java.sql.DriverManager;
    +import java.sql.PreparedStatement;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.util.Properties;
    +import org.apache.phoenix.expression.function.JsonArrayLengthFunction;
    +import org.apache.phoenix.util.PropertiesUtil;
    +import org.junit.Test;
    +
    +/**
    + * End to end test for {@link JsonArrayLengthFunction}.
    + *
    + */
    +public class JsonArrayLengthFunctionIT extends BaseHBaseManagedTimeIT {
    +
    +	@Test
    +	public void testJsonArrayLengthWithWhereClause() throws Exception {
    +		Connection conn = getConnection();
    +		String json = "[1,2,3]";
    +		String pk = "valueOne";
    +		try {
    +			populateJsonTable(conn, json, pk);
    +
    +			String selectQuery = "SELECT col1 FROM testJson WHERE json_array_length(col1) = 3";
    +			PreparedStatement stmt = conn.prepareStatement(selectQuery);
    +			ResultSet rs = stmt.executeQuery();
    +			assertTrue(rs.next());
    +			assertEquals("Json data read from DB is not as expected.", json,
    +					rs.getString(1));
    +			assertFalse(rs.next());
    +
    +		} finally {
    +			conn.close();
    +		}
    +	}
    +
    +	@Test
    +	public void testJsonArrayLengthWhenFirstArgumentIsJsonString()
    +			throws Exception {
    +		Connection conn = getConnection();
    +		String json = "[1,2,true,[\"string\",3]]";
    +		String pk = "valueOne";
    +		try {
    +			populateJsonTable(conn, json, pk);
    +
    +			String selectQuery = "SELECT json_array_length(col1) FROM testJson WHERE pk = 'valueOne'";
    +			PreparedStatement stmt = conn.prepareStatement(selectQuery);
    +			ResultSet rs = stmt.executeQuery();
    +			assertTrue(rs.next());
    +			assertEquals("Json data read from DB is not as expected.",
    +					4, rs.getInt(1));
    +
    +			assertFalse(rs.next());
    +
    +		} finally {
    +			conn.close();
    +		}
    +	}
    +
    +    @Test
    +    public void testJsonArrayElementsWithWhereClause() throws Exception {
    --- End diff --
    
    Can you add a test that verifies json_array_elements returns an array correctly ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message