Skip to content

Commit

Permalink
Merge branch 'BugFix/44064_ReloadSolutionGettingerror'
Browse files Browse the repository at this point in the history
  • Loading branch information
GokulBothe99 committed Nov 18, 2024
2 parents 7cb950c + 01e6a68 commit ce2d754
Showing 1 changed file with 70 additions and 39 deletions.
109 changes: 70 additions & 39 deletions Ginger/GingerCoreNET/Database/NoSqlBase/GingerHbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ limitations under the License.

using Amdocs.Ginger.Common;
using Applitools.Utils;
using Cassandra.DataStax.Graph.Internal;
using GingerCore.Actions;
using Microsoft.Azure.Cosmos.Core;
using Microsoft.CodeAnalysis.VisualBasic.Syntax;
using Microsoft.HBase.Client;
using MongoDB.Driver;
using OctaneStdSDK.Entities.Base;
Expand All @@ -29,6 +32,7 @@ limitations under the License.
using System.Text;
using System.Threading.Tasks;
using static GingerCore.Actions.ActDBValidation;
using static Microsoft.HBase.Client.Filters.CompareFilter;
using BinaryComparator = Microsoft.HBase.Client.Filters.BinaryComparator;
using Cell = org.apache.hadoop.hbase.rest.protobuf.generated.Cell;
using CompareFilter = Microsoft.HBase.Client.Filters.CompareFilter;
Expand All @@ -40,6 +44,7 @@ limitations under the License.
using RequestOptions = Microsoft.HBase.Client.RequestOptions;
using Scanner = org.apache.hadoop.hbase.rest.protobuf.generated.Scanner;
using SingleColumnValueFilter = Microsoft.HBase.Client.Filters.SingleColumnValueFilter;

namespace GingerCore.NoSqlBase
{

Expand Down Expand Up @@ -200,7 +205,23 @@ public Filter getFilter(string op, string family, string fieldName, string field
CompareFilter.CompareOp compareOp = Enum.GetValues<CompareFilter.CompareOp>().FirstOrDefault(e => string.Equals(e.ToString(), op));
if (string.Equals(compareOp.ToString(), op))
{
return new SingleColumnValueFilter(Encoding.UTF8.GetBytes(family), Encoding.UTF8.GetBytes(fieldName), compareOp, Encoding.UTF8.GetBytes(fieldValue));


if (fieldValue.StartsWith('\'') && fieldValue.EndsWith('\''))
{
fieldValue = fieldValue.Trim('\'');
return new SingleColumnValueFilter(Encoding.UTF8.GetBytes(family), Encoding.UTF8.GetBytes(fieldName), compareOp, Encoding.UTF8.GetBytes(fieldValue), filterIfMissing: true);
}
else if (fieldValue.Contains('.'))
{
return new SingleColumnValueFilter(Encoding.UTF8.GetBytes(family), Encoding.UTF8.GetBytes(fieldName), compareOp, System.BitConverter.GetBytes(double.Parse(fieldValue)), filterIfMissing: true);
}
else
{
var longBytes = System.BitConverter.GetBytes(long.Parse(fieldValue));
Array.Reverse(longBytes);
return new SingleColumnValueFilter(Encoding.UTF8.GetBytes(family), Encoding.UTF8.GetBytes(fieldName), compareOp, longBytes, filterIfMissing: true);
}
}
else if (string.Equals("RegexComp", op))
{
Expand Down Expand Up @@ -426,41 +447,38 @@ public override async void PerformDBAction()
Reporter.ToLog(eLogLevel.ERROR, "The Query value can not be empty");
break;
}

if (SQLCalculated.Contains("where"))
{
table = SQLCalculated.Substring(SQLCalculated.IndexOf("from") + 4, (SQLCalculated.IndexOf("where") - SQLCalculated.IndexOf("from") - 4)).Trim();
wherepart = SQLCalculated[(SQLCalculated.IndexOf("where") + 5)..];
familyName = actionClient.GetTableSchemaAsync(table, null).Result.columns.ToList()[0].name;
scanner = getScanner(wherepart, familyName);
var familyNameList = actionClient.GetTableSchemaAsync(table, null).Result.columns.ToList();

CellSet next;

scanner = null;

foreach (var i in familyNameList)
{
familyName = i.name;
scanner = getScanner(wherepart, familyName);
scanInfo = actionClient.CreateScannerAsync(table, scanner, requestOption).Result;

if ((next = actionClient.ScannerGetNextAsync(scanInfo, requestOption).Result) != null)

Check warning on line 466 in Ginger/GingerCoreNET/Database/NoSqlBase/GingerHbase.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Database/NoSqlBase/GingerHbase.cs#L466

Remove this useless assignment to local variable 'next'.
{
break;
}

}

}
else
{

scanner = new Scanner();
table = SQLCalculated[(SQLCalculated.IndexOf("from") + 4)..].Trim();
}

scanInfo = actionClient.CreateScannerAsync(table, scanner, requestOption).Result;
int path1 = 1;


//var tableDescriptor = await actionClient.GetTableSchemaAsync(table, null);
//Console.WriteLine($"Table: {tableDescriptor.Name}");

// Iterating over column families
//foreach (var columnFamily in tableDescriptor..ColumnFamilies)
//{
// Console.WriteLine($"Column Family: {columnFamily.Name}");

// // Here you can add logic to infer or define data types.
// // HBase doesn't store data types inherently, you may need to
// // map them based on your application's logic or design.
// // For instance:
// // - You might have a convention where specific column families
// // relate to specific data types.
//}
if (SQLCalculated.Contains('*'))
{

Expand All @@ -478,24 +496,16 @@ public override async void PerformDBAction()
{
foreach (Cell c in cells)
{

try
{
Act.AddOrUpdateReturnParamActualWithPath(ExtractColumnName(c.column), DisplayInferredTypeAndValue(c.data), path1.ToString());
}
catch (Exception)
{

// throw;
}

{ }

Check warning on line 504 in Ginger/GingerCoreNET/Database/NoSqlBase/GingerHbase.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Database/NoSqlBase/GingerHbase.cs#L504

Either remove or fill this block of code.
}
}
catch (Exception)
{

// throw;
}
{ }
path1++;
}

Expand All @@ -504,10 +514,6 @@ public override async void PerformDBAction()
}
else
{

int i = SQLCalculated.IndexOf("select");
int j = SQLCalculated.IndexOf("from");

string[] selectedcols = SQLCalculated.Trim().Substring((SQLCalculated.IndexOf("select") + 6), SQLCalculated.IndexOf("from") - SQLCalculated.IndexOf("select") - 6).Split(",");
CellSet next;
List<string> list = [];
Expand Down Expand Up @@ -559,6 +565,8 @@ public override async void PerformDBAction()

}



public enum DataType
{
Int,
Expand All @@ -577,6 +585,10 @@ public static string DisplayInferredTypeAndValue(byte[] byteArray)
{
return "";
}
if (byteArray.All(y => y == 0))
{
return "0";
}
DataType inferredType = DataType.String;
if (byteArray != null && byteArray.Length > 0 && (byteArray[0] == 0))
{
Expand All @@ -588,6 +600,23 @@ public static string DisplayInferredTypeAndValue(byte[] byteArray)
}
object value = ConvertByteArrayToType(byteArray, inferredType);


if (inferredType == DataType.Double && !(Double.IsNaN(double.Parse(value.ToString())) || Double.IsInfinity(double.Parse(value.ToString()))))
{
//Not a double
inferredType = DataType.Long;
value = ConvertByteArrayToType(byteArray, inferredType);

}

if (inferredType == DataType.Long && (Double.IsNaN(double.Parse(value.ToString())) || Double.IsInfinity(double.Parse(value.ToString()))))
{
//Not a Long
inferredType = DataType.Double;
value = ConvertByteArrayToType(byteArray, inferredType);

}

if (inferredType == DataType.Long && value != null && value.ToString()[0] == '-' && value.ToString().Length >= 20)
{
inferredType = DataType.Double;
Expand Down Expand Up @@ -621,11 +650,11 @@ public static DataType InferDataType(byte[] byteArray)
return DataType.Unknown;

case 8:
// Potentially long or double
if (System.BitConverter.ToDouble(byteArray, 0) != 0)
return DataType.Double;
if (System.BitConverter.ToInt64(byteArray, 0) != 0) // Example heuristic, adjust as necessary
return DataType.Long; // could be a long
if (System.BitConverter.ToDouble(byteArray, 0) != 0)
return DataType.Double; // could be a double
// could be a double

return DataType.Unknown;

Expand All @@ -635,6 +664,8 @@ public static DataType InferDataType(byte[] byteArray)
}
}



public static object ConvertByteArrayToType(byte[] byteArray, DataType dataType)
{
return dataType switch
Expand Down

0 comments on commit ce2d754

Please sign in to comment.