mirror of https://github.com/apache/druid.git
Change the default format from OBJECT to OBJECTLINES (#14700)
This commit is contained in:
parent
21d023b62b
commit
339b8d959f
|
@ -773,7 +773,7 @@ public class SqlStatementResource
|
||||||
) throws IOException
|
) throws IOException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
try (final ResultFormat.Writer writer = ResultFormat.OBJECT.createFormatter(os, jsonMapper)) {
|
try (final ResultFormat.Writer writer = ResultFormat.OBJECTLINES.createFormatter(os, jsonMapper)) {
|
||||||
Yielder<Object[]> yielder = results.get();
|
Yielder<Object[]> yielder = results.get();
|
||||||
List<ColumnNameAndTypes> rowSignature = signature.get();
|
List<ColumnNameAndTypes> rowSignature = signature.get();
|
||||||
writer.writeResponseStart();
|
writer.writeResponseStart();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.apache.druid.msq.sql;
|
package org.apache.druid.msq.sql;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.apache.calcite.sql.type.SqlTypeName;
|
import org.apache.calcite.sql.type.SqlTypeName;
|
||||||
|
@ -49,8 +50,10 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.StreamingOutput;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -315,26 +318,52 @@ public class SqlMSQStatementResourcePostTest extends MSQTestBase
|
||||||
SqlStatementResourceTest.makeOkRequest()
|
SqlStatementResourceTest.makeOkRequest()
|
||||||
).getEntity();
|
).getEntity();
|
||||||
|
|
||||||
|
assertExpectedResults(
|
||||||
List<Map<String, Object>> rows = new ArrayList<>();
|
"{\"cnt\":1,\"dim1\":\"\"}\n"
|
||||||
rows.add(ImmutableMap.of("cnt", 1, "dim1", ""));
|
+ "{\"cnt\":1,\"dim1\":\"10.1\"}\n"
|
||||||
rows.add(ImmutableMap.of("cnt", 1, "dim1", "10.1"));
|
+ "{\"cnt\":1,\"dim1\":\"2\"}\n"
|
||||||
rows.add(ImmutableMap.of("cnt", 1, "dim1", "2"));
|
+ "{\"cnt\":1,\"dim1\":\"1\"}\n"
|
||||||
rows.add(ImmutableMap.of("cnt", 1, "dim1", "1"));
|
+ "{\"cnt\":1,\"dim1\":\"def\"}\n"
|
||||||
rows.add(ImmutableMap.of("cnt", 1, "dim1", "def"));
|
+ "{\"cnt\":1,\"dim1\":\"abc\"}\n"
|
||||||
rows.add(ImmutableMap.of("cnt", 1, "dim1", "abc"));
|
+ "\n",
|
||||||
|
resource.doGetResults(
|
||||||
Assert.assertEquals(rows, SqlStatementResourceTest.getResultRowsFromResponse(resource.doGetResults(
|
|
||||||
sqlStatementResult.getQueryId(),
|
sqlStatementResult.getQueryId(),
|
||||||
null,
|
null,
|
||||||
SqlStatementResourceTest.makeOkRequest()
|
SqlStatementResourceTest.makeOkRequest()
|
||||||
)));
|
),
|
||||||
|
objectMapper);
|
||||||
|
|
||||||
Assert.assertEquals(rows, SqlStatementResourceTest.getResultRowsFromResponse(resource.doGetResults(
|
assertExpectedResults(
|
||||||
|
"{\"cnt\":1,\"dim1\":\"\"}\n"
|
||||||
|
+ "{\"cnt\":1,\"dim1\":\"10.1\"}\n"
|
||||||
|
+ "{\"cnt\":1,\"dim1\":\"2\"}\n"
|
||||||
|
+ "{\"cnt\":1,\"dim1\":\"1\"}\n"
|
||||||
|
+ "{\"cnt\":1,\"dim1\":\"def\"}\n"
|
||||||
|
+ "{\"cnt\":1,\"dim1\":\"abc\"}\n"
|
||||||
|
+ "\n",
|
||||||
|
resource.doGetResults(
|
||||||
sqlStatementResult.getQueryId(),
|
sqlStatementResult.getQueryId(),
|
||||||
0L,
|
0L,
|
||||||
SqlStatementResourceTest.makeOkRequest()
|
SqlStatementResourceTest.makeOkRequest()
|
||||||
)));
|
),
|
||||||
|
objectMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertExpectedResults(String expectedResult, Response resultsResponse, ObjectMapper objectMapper) throws IOException
|
||||||
|
{
|
||||||
|
byte[] bytes = responseToByteArray(resultsResponse, objectMapper);
|
||||||
|
Assert.assertEquals(expectedResult, new String(bytes, StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] responseToByteArray(Response resp, ObjectMapper objectMapper) throws IOException
|
||||||
|
{
|
||||||
|
if (resp.getEntity() instanceof StreamingOutput) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
((StreamingOutput) resp.getEntity()).write(baos);
|
||||||
|
return baos.toByteArray();
|
||||||
|
} else {
|
||||||
|
return objectMapper.writeValueAsBytes(resp.getEntity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -95,7 +95,6 @@ import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -747,33 +746,32 @@ public class SqlStatementResourceTest extends MSQTestBase
|
||||||
Response resultsResponse = resource.doGetResults(FINISHED_SELECT_MSQ_QUERY, 0L, makeOkRequest());
|
Response resultsResponse = resource.doGetResults(FINISHED_SELECT_MSQ_QUERY, 0L, makeOkRequest());
|
||||||
Assert.assertEquals(Response.Status.OK.getStatusCode(), resultsResponse.getStatus());
|
Assert.assertEquals(Response.Status.OK.getStatusCode(), resultsResponse.getStatus());
|
||||||
|
|
||||||
List<Map<String, Object>> rows = new ArrayList<>();
|
String expectedResult = "{\"_time\":123,\"alias\":\"foo\",\"market\":\"bar\"}\n"
|
||||||
rows.add(ROW1);
|
+ "{\"_time\":234,\"alias\":\"foo1\",\"market\":\"bar1\"}\n\n";
|
||||||
rows.add(ROW2);
|
|
||||||
|
|
||||||
Assert.assertEquals(rows, getResultRowsFromResponse(resultsResponse));
|
assertExpectedResults(expectedResult, resultsResponse);
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
Response.Status.OK.getStatusCode(),
|
Response.Status.OK.getStatusCode(),
|
||||||
resource.deleteQuery(FINISHED_SELECT_MSQ_QUERY, makeOkRequest()).getStatus()
|
resource.deleteQuery(FINISHED_SELECT_MSQ_QUERY, makeOkRequest()).getStatus()
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.assertEquals(
|
assertExpectedResults(
|
||||||
rows,
|
expectedResult,
|
||||||
getResultRowsFromResponse(resource.doGetResults(
|
resource.doGetResults(
|
||||||
FINISHED_SELECT_MSQ_QUERY,
|
FINISHED_SELECT_MSQ_QUERY,
|
||||||
0L,
|
0L,
|
||||||
makeOkRequest()
|
makeOkRequest()
|
||||||
))
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.assertEquals(
|
assertExpectedResults(
|
||||||
rows,
|
expectedResult,
|
||||||
getResultRowsFromResponse(resource.doGetResults(
|
resource.doGetResults(
|
||||||
FINISHED_SELECT_MSQ_QUERY,
|
FINISHED_SELECT_MSQ_QUERY,
|
||||||
null,
|
null,
|
||||||
makeOkRequest()
|
makeOkRequest()
|
||||||
))
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -782,6 +780,12 @@ public class SqlStatementResourceTest extends MSQTestBase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertExpectedResults(String expectedResult, Response resultsResponse) throws IOException
|
||||||
|
{
|
||||||
|
byte[] bytes = SqlResourceTest.responseToByteArray(resultsResponse);
|
||||||
|
Assert.assertEquals(expectedResult, new String(bytes, StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailedMSQQuery()
|
public void testFailedMSQQuery()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue