-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Row filtering and Column splitting logic.
Now its possible to create additional columns which were not present in original data file. Also possible to reject rows that don't meet certain criteria.
- Loading branch information
Showing
20 changed files
with
970 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdysTech.Influxer.Config | ||
{ | ||
public class FilterTransformation : ConfigurationElement, ITransform, IConfigurationElementCollectionElement | ||
{ | ||
|
||
[ConfigurationProperty ("RegEx")] | ||
public string RegEx | ||
{ | ||
get { return (string) this["RegEx"]; } | ||
set { this["RegEx"] = value; } | ||
} | ||
|
||
[ConfigurationProperty ("IsDefault")] | ||
public bool IsDefault | ||
{ | ||
get { return (bool) this["IsDefault"]; } | ||
set { this["IsDefault"] = value; } | ||
} | ||
|
||
[ConfigurationProperty ("DefaultValue")] | ||
public string DefaultValue | ||
{ | ||
get { return (string) this["DefaultValue"]; } | ||
set { this["DefaultValue"] = value; } | ||
} | ||
|
||
Regex _extractPattern; | ||
public Regex ExtractPattern | ||
{ | ||
get | ||
{ | ||
if (_extractPattern == null && !String.IsNullOrWhiteSpace (RegEx)) | ||
{ | ||
_extractPattern = new Regex (RegEx, RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||
} | ||
return _extractPattern; | ||
} | ||
} | ||
|
||
|
||
|
||
public bool CanTransform (string content) | ||
{ | ||
if (IsDefault) return true; | ||
|
||
return !String.IsNullOrWhiteSpace (content) ? ExtractPattern.IsMatch (content) : false; | ||
|
||
} | ||
|
||
public string Transform (string content) | ||
{ | ||
if (CanTransform (content)) | ||
{ | ||
throw new InvalidDataException (String.Format ("{0} filtered out as per rule {1}", content, RegEx)); | ||
} | ||
return string.Empty; | ||
} | ||
|
||
public string GetKey () | ||
{ | ||
return this.GetHashCode ().ToString (); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdysTech.Influxer.Config | ||
{ | ||
public interface ISplit | ||
{ | ||
bool CanSplit(string content); | ||
Dictionary<ColumnConfig, string> Split(string content); | ||
IList<ColumnConfig> SubColumns { get; } | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdysTech.Influxer.Config | ||
{ | ||
public enum SplitType | ||
{ | ||
Delimited, | ||
FixedWidth | ||
} | ||
|
||
public class Splitter : ConfigurationElement, ISplit | ||
{ | ||
|
||
[ConfigurationProperty ("Type")] | ||
public SplitType Type | ||
{ | ||
get { return (SplitType) this["Type"]; } | ||
set { this["Type"] = value; } | ||
} | ||
|
||
[ConfigurationProperty ("Width")] | ||
public int Width | ||
{ | ||
get { return (int) this["Width"]; } | ||
set { this["Width"] = value; } | ||
} | ||
|
||
|
||
[ConfigurationProperty ("Delimiter")] | ||
public string Delimiter | ||
{ | ||
get { return (string) this["Delimiter"]; } | ||
set { this["Delimiter"] = value; } | ||
} | ||
|
||
[ConfigurationProperty ("SplitColumns")] | ||
public ColumnLayoutConfig SubColumnsConfig | ||
{ | ||
get { return (ColumnLayoutConfig) this["SplitColumns"]; } | ||
set { this["SplitColumns"] = value; } | ||
} | ||
|
||
|
||
|
||
Regex _splitPattern; | ||
public Regex SplitPattern | ||
{ | ||
get | ||
{ | ||
if (Type == SplitType.Delimited && _splitPattern == null && !String.IsNullOrWhiteSpace (Delimiter)) | ||
{ | ||
_splitPattern = new Regex (Delimiter, RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||
} | ||
return _splitPattern; | ||
} | ||
} | ||
|
||
public IList<ColumnConfig> SubColumns | ||
{ | ||
get | ||
{ | ||
var ls = new List<ColumnConfig> (SubColumnsConfig.Count + SubColumnsConfig.Select (t => t.SplitConfig?.SubColumnsConfig?.Count).Sum ().Value); | ||
ls.AddRange (SubColumnsConfig); | ||
ls.AddRange (SubColumnsConfig.SelectMany (t => t.SplitConfig?.SubColumns)); | ||
return ls; | ||
} | ||
} | ||
|
||
public bool CanSplit (string content) | ||
{ | ||
if (String.IsNullOrWhiteSpace (content)) return false; | ||
|
||
return (Type == SplitType.FixedWidth) ? content.Length > Width : SplitPattern.IsMatch (content); | ||
|
||
} | ||
|
||
public Dictionary<ColumnConfig, string> Split (string content) | ||
{ | ||
IList<string> values = null; | ||
if (Type == SplitType.FixedWidth) | ||
values = content.SplitFixedWidth (Width).ToList (); | ||
else | ||
values = SplitPattern.Split (content).ToList (); | ||
var ret = new Dictionary<ColumnConfig, string> (); | ||
for (int i = 0; i < SubColumnsConfig.Count; i++) | ||
{ | ||
if (SubColumnsConfig[i].SplitConfig?.SubColumns?.Count > 0) | ||
{ | ||
var subColumns = SubColumnsConfig[i].SplitConfig.Split (values[i]); | ||
foreach (var c in subColumns) | ||
ret.Add (c.Key, c.Value); | ||
} | ||
else | ||
{ | ||
ret.Add (SubColumnsConfig[i], values[i]); | ||
} | ||
} | ||
return ret; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.