Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ private Optional<ResultSetInformation> getSampleResults(
rows = 0L;
size = 0L;
for (PageInformation pageInformation : pageList.get()) {
rows += pageInformation.getNumRows();
size += pageInformation.getSizeInBytes();
rows += pageInformation.getNumRows() != null ? pageInformation.getNumRows() : 0L;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

From the code, it seems like numRows can't be null, so can we modify the PageInformation instead to remove the Nullable tag for numRows, convert it to a long, and remove the check here?

Similarly, with this change, we aren't using the nullity of PageInformation::sizeOfBytes() anywhere apart from this check, therefore can we convert it to a primitive long, populate it as 0 instead of null, remove the Nullable and clean up the special handling here?

Since we don't require any special ability of the boxed types, it seems better to clean them up. WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since page information is serialized as json in the SqlStatementResult, I prefer PageInformation#numRows and sizeOfBytes to be Long. That way if they are not populated for whatever reason, they are not sent across to the end users.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, please add @JsonInclude(JsonInclude.Include.NON_NULL) to the Jackson annotations of the members of PageInformation. By default, we do serialize and present null values to the user. So per the current behavior, page information would get serialized as {"numRows":null,"sizeInBytes":null,"id":5}.

Approving the PR since the fix is not related to the current change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Will do that in the next PR.

size += pageInformation.getSizeInBytes() != null ? pageInformation.getSizeInBytes() : 0L;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.druid.common.config.NullHandling;
import org.apache.druid.error.DruidException;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.msq.indexing.MSQControllerTask;
Expand Down Expand Up @@ -336,6 +337,90 @@ public void testWithDurableStorage() throws IOException
)));
}

@Test
public void testInsert()
{
Response response = resource.doPost(new SqlQuery(
"insert into foo1 select __time, dim1 , count(*) as cnt from foo where dim1 is not null group by 1, 2 PARTITIONED by day clustered by dim1",
null,
false,
false,
false,
defaultAsyncContext(),
null
), SqlStatementResourceTest.makeOkRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

SqlStatementResult actual = (SqlStatementResult) response.getEntity();


SqlStatementResult expected = new SqlStatementResult(
actual.getQueryId(),
SqlStatementState.SUCCESS,
MSQTestOverlordServiceClient.CREATED_TIME,
null,
MSQTestOverlordServiceClient.DURATION,
new ResultSetInformation(NullHandling.sqlCompatible() ? 6L : 5L, 0L, null, "foo1", null, null),
null
);
Assert.assertEquals(expected, actual);

Response getResponse = resource.doGetStatus(actual.getQueryId(), SqlStatementResourceTest.makeOkRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Assert.assertEquals(expected, getResponse.getEntity());

Response resultsResponse = resource.doGetResults(
actual.getQueryId(),
null,
SqlStatementResourceTest.makeOkRequest()
);
Assert.assertEquals(Response.Status.OK.getStatusCode(), resultsResponse.getStatus());
Assert.assertNull(resultsResponse.getEntity());
}


@Test
public void testReplaceAll()
{
Response response = resource.doPost(new SqlQuery(
"replace into foo1 overwrite all select __time, dim1 , count(*) as cnt from foo where dim1 is not null group by 1, 2 PARTITIONED by day clustered by dim1",
null,
false,
false,
false,
defaultAsyncContext(),
null
), SqlStatementResourceTest.makeOkRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

SqlStatementResult actual = (SqlStatementResult) response.getEntity();


SqlStatementResult expected = new SqlStatementResult(
actual.getQueryId(),
SqlStatementState.SUCCESS,
MSQTestOverlordServiceClient.CREATED_TIME,
null,
MSQTestOverlordServiceClient.DURATION,
new ResultSetInformation(NullHandling.sqlCompatible() ? 6L : 5L, 0L, null, "foo1", null, null),
null
);
Assert.assertEquals(expected, actual);

Response getResponse = resource.doGetStatus(actual.getQueryId(), SqlStatementResourceTest.makeOkRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Assert.assertEquals(expected, getResponse.getEntity());

Response resultsResponse = resource.doGetResults(
actual.getQueryId(),
null,
SqlStatementResourceTest.makeOkRequest()
);
Assert.assertEquals(Response.Status.OK.getStatusCode(), resultsResponse.getStatus());
Assert.assertNull(resultsResponse.getEntity());
}


private static Map<String, Object> defaultAsyncContext()
{
Map<String, Object> context = new HashMap<String, Object>();
Expand Down