Skip to content

Commit 4d0d497

Browse files
committed
Temporary changes to the TextLengthExplorer
1. Should have used `override` instead of `new` in `Explore()` method definition. 2. The `TextLengthExplorer` crashed when used with a column that was considered 'isolating'. This change prevents this by checking the `show columns` query. 3. Fixed usage of the metricNamePrefix.
1 parent d2366cb commit 4d0d497

1 file changed

Lines changed: 40 additions & 3 deletions

File tree

src/explorer/Explorers/TextLengthExplorer.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
namespace Explorer.Explorers
22
{
3+
using System.Linq;
4+
using System.Text.Json;
35
using System.Threading.Tasks;
46

57
using Diffix;
68
using Explorer.Common;
79

810
internal class TextLengthExplorer : IntegerColumnExplorer
911
{
10-
private readonly string metricNamePrefix = "text.length";
12+
private readonly string metricNamePrefix;
1113

12-
public TextLengthExplorer(string metricNamePrefix = "")
14+
public TextLengthExplorer(string metricNamePrefix = "text.length")
1315
{
1416
this.metricNamePrefix = metricNamePrefix;
1517
}
1618

17-
public new async Task Explore(DConnection conn, ExplorerContext ctx)
19+
public override async Task Explore(DConnection conn, ExplorerContext ctx)
1820
{
21+
var isolators = await conn.Exec(new IsIsolatorColumn(ctx.Table));
22+
var isIsolatorColumn = isolators.Rows.First(r => r.Item1 == ctx.Column).Item2;
23+
24+
if (isIsolatorColumn)
25+
{
26+
// TODO: Log the fact that we are aborting here.
27+
return;
28+
}
29+
1930
var lengthContext = new ExplorerContext(ctx.Table, $"length({ctx.Column})", ctx.ColumnType);
2031

2132
await base.Explore(conn, lengthContext);
@@ -29,5 +40,31 @@ public override void PublishMetric(ExploreMetric metric)
2940
}
3041
base.PublishMetric(metric);
3142
}
43+
44+
// TODO: replace this with a component
45+
private class IsIsolatorColumn : DQuery<(string, bool)>
46+
{
47+
public IsIsolatorColumn(string table)
48+
{
49+
QueryStatement = $"show columns from {table}";
50+
}
51+
52+
public string QueryStatement { get; }
53+
54+
public (string, bool) ParseRow(ref Utf8JsonReader reader)
55+
{
56+
reader.Read();
57+
var name = reader.GetString();
58+
59+
reader.Read(); // ignore data type
60+
61+
reader.Read();
62+
var isolator = reader.GetString() == "true";
63+
64+
reader.Read(); // ignore key type
65+
66+
return (name, isolator);
67+
}
68+
}
3269
}
3370
}

0 commit comments

Comments
 (0)