using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace ZKLT.Hadoop.Model
{
///
/// 命令函数
///
public class HDP_CommandAction
{
///
/// 当前日期
///
public const string DATENOW = "DATE_NOW()";
///
/// 唯一码
///
public const string UUID = "UUID()";
///
/// 转换命令
///
/// 函数
/// 参数
/// 命令
public static object Convert(string action, JToken param)
{
if (action == DATENOW)
{
return DateTime.Now;
}
else if (action == UUID)
{
return Guid.NewGuid().ToString();
}
else {
return action;
}
}
///
/// 列转换
///
/// 列
/// 参数
/// 公式
///
public static string ColConvert(HDP_Column column, Dictionary param,object value) {
string _guid;
if (value is string) {
string _action = value.ToString()!;
Regex _regex1 = new Regex(@"(?<=(\+\=))[\d\.]+");
if(_regex1.IsMatch(_action))
{
_guid = Guid.NewGuid().ToString("N");
param.Add(_guid,_regex1.Match(_action).Value);
return @$"`{column.Key}` + @{_guid}";
}
Regex _regex2 = new Regex(@"(?<=(\-\=))[\d\.]+");
if (_regex2.IsMatch(_action))
{
_guid = Guid.NewGuid().ToString("N");
param.Add(_guid, _regex2.Match(_action).Value);
return @$"`{column.Key}` - @{_guid}";
}
}
param.Add(column.Key!, value);
return $@"@{column.Key}";
}
}
}