This commit is contained in:
Zoltan Haindrich 2024-07-19 11:36:51 +00:00
parent 361149b097
commit 31e97324ce
6 changed files with 425 additions and 10 deletions

View File

@ -95,6 +95,7 @@ public class MSQDruidMeta extends DruidMeta
String str = objectMapper String str = objectMapper
.writerWithDefaultPrettyPrinter() .writerWithDefaultPrettyPrinter()
.writeValueAsString(payload.getStages()); .writeValueAsString(payload.getStages());
str=str.replaceAll(taskId, "<taskId>");
DruidHook.dispatch(DruidHook.MSQ_PLAN, str); DruidHook.dispatch(DruidHook.MSQ_PLAN, str);
} }
catch (JsonProcessingException e) { catch (JsonProcessingException e) {

View File

@ -19,7 +19,7 @@ order by 1;
[ { [ {
"stageNumber" : 0, "stageNumber" : 0,
"definition" : { "definition" : {
"id" : "query-9d38a860-0463-4c5d-b7ed-b2d4e4a0ac6c_0", "id" : "<taskId>_0",
"input" : [ { "input" : [ {
"type" : "table", "type" : "table",
"dataSource" : "wikipedia", "dataSource" : "wikipedia",
@ -94,7 +94,7 @@ order by 1;
"finalize" : true, "finalize" : true,
"maxParseExceptions" : 0, "maxParseExceptions" : 0,
"plannerStrategy" : "DECOUPLED", "plannerStrategy" : "DECOUPLED",
"sqlQueryId" : "9d38a860-0463-4c5d-b7ed-b2d4e4a0ac6c", "sqlQueryId" : "dd89814f-71a0-4968-ae18-7fb16b354a42",
"sqlStringifyArrays" : false "sqlStringifyArrays" : false
} }
} }
@ -127,13 +127,13 @@ order by 1;
"partitionCount" : 1, "partitionCount" : 1,
"shuffle" : "globalSort", "shuffle" : "globalSort",
"output" : "localStorage", "output" : "localStorage",
"startTime" : "2024-07-19T04:30:50.581Z", "startTime" : "2024-07-19T11:35:14.021Z",
"duration" : 742, "duration" : 727,
"sort" : true "sort" : true
}, { }, {
"stageNumber" : 1, "stageNumber" : 1,
"definition" : { "definition" : {
"id" : "query-9d38a860-0463-4c5d-b7ed-b2d4e4a0ac6c_1", "id" : "<taskId>_1",
"input" : [ { "input" : [ {
"type" : "stage", "type" : "stage",
"stage" : 0 "stage" : 0
@ -200,7 +200,7 @@ order by 1;
"finalize" : true, "finalize" : true,
"maxParseExceptions" : 0, "maxParseExceptions" : 0,
"plannerStrategy" : "DECOUPLED", "plannerStrategy" : "DECOUPLED",
"sqlQueryId" : "9d38a860-0463-4c5d-b7ed-b2d4e4a0ac6c", "sqlQueryId" : "dd89814f-71a0-4968-ae18-7fb16b354a42",
"sqlStringifyArrays" : false "sqlStringifyArrays" : false
} }
} }
@ -221,9 +221,9 @@ order by 1;
"workerCount" : 1, "workerCount" : 1,
"partitionCount" : 1, "partitionCount" : 1,
"output" : "localStorage", "output" : "localStorage",
"startTime" : "2024-07-19T04:30:51.323Z", "startTime" : "2024-07-19T11:35:14.748Z",
"duration" : 2 "duration" : 2
} ] } ]tid:query-dd89814f-71a0-4968-ae18-7fb16b354a42
!msqPlan !msqPlan
LogicalSort(sort0=[$0], dir0=[ASC]) LogicalSort(sort0=[$0], dir0=[ASC])
LogicalAggregate(group=[{0}], cnt=[COUNT($1)], aall=[COUNT()]) LogicalAggregate(group=[{0}], cnt=[COUNT($1)], aall=[COUNT()])

View File

@ -32,7 +32,7 @@ import javax.annotation.Nullable;
* Package-private since it is not intended to be used outside that narrow use case. In other cases where passing * Package-private since it is not intended to be used outside that narrow use case. In other cases where passing
* around information about column types is important, use {@link ColumnType} instead. * around information about column types is important, use {@link ColumnType} instead.
*/ */
class ColumnSignature public /*FIXME*/ class ColumnSignature
{ {
private final String name; private final String name;

View File

@ -188,7 +188,7 @@ public class RowSignature implements ColumnInspector
} }
@JsonValue @JsonValue
private List<ColumnSignature> asColumnSignatures() public List<ColumnSignature> asColumnSignatures()
{ {
final List<ColumnSignature> retVal = new ArrayList<>(); final List<ColumnSignature> retVal = new ArrayList<>();

View File

@ -0,0 +1,212 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.druid.quidem;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import org.apache.druid.msq.indexing.report.MSQResultsReport.ColumnAndType;
import org.apache.druid.segment.column.ColumnSignature;
import org.apache.druid.segment.column.ColumnType;
import org.apache.druid.segment.column.RowSignature;
import org.junit.Test;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class A11
{
static class CustomCollapedIntender implements DefaultPrettyPrinter.Indenter
{
boolean isInside = false;
@Override
public boolean isInline()
{
return false;// getDelegate().isInline();
}
private DefaultPrettyPrinter.Indenter getDelegate()
{
if (isInside) {
return new DefaultPrettyPrinter.NopIndenter();
} else {
return DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
}
}
@Override
public void writeIndentation(JsonGenerator g, int level) throws IOException
{
if (isX(g)) {
}
isInside = isX(g);
if (isInside) {
int asd = 1;
}
getDelegate().writeIndentation(g, level);
}
private boolean isX(JsonGenerator g)
{
Object v = g.getCurrentValue();
return v instanceof ColumnSignature;
// return false;
// return v instanceof RowSignature;
// return g.getCurrentValue() instanceof List;
}
}
static class aa extends DefaultPrettyPrinter
{
public aa()
{
super();
_objectIndenter = new CustomCollapedIntender();
}
@Override
public DefaultPrettyPrinter createInstance()
{
return new aa();
}
// @Override
// public void writeObjectEntrySeparator(JsonGenerator g) throws IOException
// {
// g.writeRaw(_separators.getObjectEntrySeparator());
// _objectIndenter.writeIndentation(g, _nesting);
// }
@Override
public void writeStartArray(JsonGenerator g) throws IOException
{
Object cv = g.getCurrentValue();
if (isX(g)) {
g.setPrettyPrinter(new MinimalPrettyPrinter());
}
super.writeStartArray(g);
}
@Override
public void writeObjectEntrySeparator(JsonGenerator g) throws IOException
{
super.writeObjectEntrySeparator(g);
}
@Override
public void writeStartObject(JsonGenerator g) throws IOException
{
super.writeStartObject(g);
}
public void writeEndObject1(JsonGenerator g, int nrOfEntries) throws IOException
{
Indenter old = _objectIndenter;
if (isX(g)) {
_objectIndenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
}
super.writeEndObject(g, nrOfEntries);
if (isX(g)) {
_objectIndenter = old;
}
}
private boolean isX(JsonGenerator g)
{
Object v = g.getCurrentValue();
return v instanceof ColumnSignature;
// return g.getCurrentValue() instanceof List;
}
@Override
public void writeEndArray(JsonGenerator g, int nrOfValues) throws IOException
{
Object cv = g.getCurrentValue();
super.writeEndArray(g, nrOfValues);
}
}
static class Asd
{
@JsonProperty
int asd = 11;
@JsonProperty
RowSignature rs;
@JsonProperty
ColumnAndType or = new ColumnAndType("Asd", ColumnType.DOUBLE);
Asd()
{
rs = RowSignature.builder()
.add("s", ColumnType.STRING)
.add("d", ColumnType.DOUBLE)
.add("d1", ColumnType.LONG)
.build();
asd = 1111;
}
}
@Test
public void sdf() throws JsonProcessingException
{
ObjectMapper om = new ObjectMapper();
om.setAnnotationIntrospector(new JacksonAnnotationIntrospector()
{
@Override
public boolean hasIgnoreMarker(final AnnotatedMember m)
{
List<String> exclusions = Arrays.asList("asd");
return exclusions.contains(m.getName()) || super.hasIgnoreMarker(m);
}
});
ObjectWriter w = om.writer(new DefaultPrettyPrinter().withObjectIndenter(new CustomCollapedIntender()));
final RowSignature.Builder builder = RowSignature.builder()
.add("s", ColumnType.STRING)
.add("d", ColumnType.DOUBLE)
.add("d1", ColumnType.LONG);
List<org.apache.druid.segment.column.ColumnSignature> cs = builder.build().asColumnSignatures();
// String s = w.writeValueAsString(builder.build());
String s = w.writeValueAsString(new Asd());
System.out.println(s);
}
}

View File

@ -0,0 +1,202 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.druid.quidem;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.apache.druid.msq.indexing.report.MSQResultsReport.ColumnAndType;
import org.apache.druid.segment.column.ColumnSignature;
import org.apache.druid.segment.column.ColumnType;
import org.apache.druid.segment.column.RowSignature;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
public class A12
{
static class MyIntender implements DefaultPrettyPrinter.Indenter
{
boolean isInside = false;
@Override
public boolean isInline()
{
return getDelegate().isInline();
}
private DefaultPrettyPrinter.Indenter getDelegate()
{
if (isInside) {
return new DefaultPrettyPrinter.NopIndenter();
} else {
return DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
}
}
@Override
public void writeIndentation(JsonGenerator g, int level) throws IOException
{
if (isX(g)) {
}
isInside = isX(g);
if (isInside) {
int asd = 1;
}
getDelegate().writeIndentation(g, level);
}
private boolean isX(JsonGenerator g)
{
Object v = g.getCurrentValue();
return v instanceof ColumnSignature;
// return false;
// return v instanceof RowSignature;
// return g.getCurrentValue() instanceof List;
}
}
static class aa extends DefaultPrettyPrinter
{
public aa()
{
super();
_objectIndenter = new MyIntender();
}
@Override
public DefaultPrettyPrinter createInstance()
{
return new aa();
}
// @Override
// public void writeObjectEntrySeparator(JsonGenerator g) throws IOException
// {
// g.writeRaw(_separators.getObjectEntrySeparator());
// _objectIndenter.writeIndentation(g, _nesting);
// }
@Override
public void writeStartArray(JsonGenerator g) throws IOException
{
Object cv = g.getCurrentValue();
if (isX(g)) {
g.setPrettyPrinter(new MinimalPrettyPrinter());
}
super.writeStartArray(g);
}
@Override
public void writeObjectEntrySeparator(JsonGenerator g) throws IOException
{
super.writeObjectEntrySeparator(g);
}
@Override
public void writeStartObject(JsonGenerator g) throws IOException
{
super.writeStartObject(g);
}
public void writeEndObject1(JsonGenerator g, int nrOfEntries) throws IOException
{
Indenter old = _objectIndenter;
if(isX(g))
{
_objectIndenter=DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
}
super.writeEndObject(g, nrOfEntries);
if(isX(g))
{
_objectIndenter=old;
}
}
private boolean isX(JsonGenerator g)
{
Object v = g.getCurrentValue();
return v instanceof ColumnSignature;
// return g.getCurrentValue() instanceof List;
}
@Override
public void writeEndArray(JsonGenerator g, int nrOfValues) throws IOException
{
Object cv = g.getCurrentValue();
super.writeEndArray(g, nrOfValues);
}
}
static class Asd
{
@JsonProperty
int asd = 11;
@JsonProperty
RowSignature rs;
@JsonProperty
ColumnAndType or = new ColumnAndType("Asd", ColumnType.DOUBLE);
Asd()
{
rs = RowSignature.builder()
.add("s", ColumnType.STRING)
.add("d", ColumnType.DOUBLE)
.add("d1", ColumnType.LONG)
.build();
asd = 1111;
}
}
@Test
public void sdf() throws JsonProcessingException
{
ObjectMapper om = new ObjectMapper();
ObjectWriter w = om.writer(new aa());
final RowSignature.Builder builder = RowSignature.builder()
.add("s", ColumnType.STRING)
.add("d", ColumnType.DOUBLE)
.add("d1", ColumnType.LONG);
List<org.apache.druid.segment.column.ColumnSignature> cs = builder.build().asColumnSignatures();
// String s = w.writeValueAsString(builder.build());
String s = w.writeValueAsString(new Asd());
System.out.println(s);
}
}