Skip to content

Commit f124f05

Browse files
authored
Adds support for table * (#710)
* allows using just a wildcard with table command, added new tests * updated wildcard fixes after related fixes done in PTH_03
1 parent 0d6869a commit f124f05

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/main/java/com/teragrep/pth_10/ast/commands/transformstatement/TableTransformation.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,19 @@ private Node tableTransformationEmitCatalyst(DPLParser.TableTransformationContex
8888

8989
@Override
9090
public Node visitT_table_wcfieldListParameter(DPLParser.T_table_wcfieldListParameterContext ctx) {
91-
List<String> listOfFields = new ArrayList<>();
91+
final List<String> listOfFields = new ArrayList<>();
9292

9393
ctx.t_table_fieldType().forEach(fieldType -> {
9494
String fieldName = ((StringNode) visit(fieldType)).toString();
9595

96-
if (!fieldName.equals("")) {
96+
if (!fieldName.isEmpty()) {
9797
listOfFields.addAll(Arrays.asList(fieldName.split(",")));
9898
}
99+
else {
100+
throw new IllegalStateException(
101+
"table command is missing field names, it requires at least one valid field name."
102+
);
103+
}
99104
});
100105

101106
return new StringListNode(listOfFields);

src/test/java/com/teragrep/pth_10/TableTransformationTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,45 @@ public void testTableWithMultipleWildcards() {
192192
);
193193
});
194194
}
195+
196+
@Test
197+
@DisabledIfSystemProperty(
198+
named = "skipSparkTest",
199+
matches = "true"
200+
)
201+
public void testTableWithOnlyWildcard() {
202+
streamingTestUtil.performDPLTest("index=index_A | table *", testFile, ds -> {
203+
final StructType expectedSchema = new StructType(new StructField[] {
204+
new StructField("_time", DataTypes.TimestampType, true, new MetadataBuilder().build()),
205+
new StructField("id", DataTypes.LongType, true, new MetadataBuilder().build()),
206+
new StructField("_raw", DataTypes.StringType, true, new MetadataBuilder().build()),
207+
new StructField("index", DataTypes.StringType, true, new MetadataBuilder().build()),
208+
new StructField("sourcetype", DataTypes.StringType, true, new MetadataBuilder().build()),
209+
new StructField("host", DataTypes.StringType, true, new MetadataBuilder().build()),
210+
new StructField("source", DataTypes.StringType, true, new MetadataBuilder().build()),
211+
new StructField("partition", DataTypes.StringType, true, new MetadataBuilder().build()),
212+
new StructField("offset", DataTypes.LongType, true, new MetadataBuilder().build())
213+
});
214+
Assertions
215+
.assertEquals(
216+
expectedSchema, ds.schema(),
217+
"Batch handler dataset contained an unexpected column arrangement !"
218+
);
219+
});
220+
}
221+
222+
@Test
223+
@DisabledIfSystemProperty(
224+
named = "skipSparkTest",
225+
matches = "true"
226+
)
227+
public void testTableWithoutFieldNames() {
228+
String q = "index=index_A | table";
229+
String e = "table command is missing field names, it requires at least one valid field name.";
230+
IllegalStateException exception = this.streamingTestUtil
231+
.performThrowingDPLTest(IllegalStateException.class, q, this.testFile, res -> {
232+
});
233+
234+
Assertions.assertEquals(e, exception.getMessage());
235+
}
195236
}

0 commit comments

Comments
 (0)