private List <TableInfo> InitializeFromTables() { List <TableInfo> result = new List <TableInfo>(); var rtes = jObject.SelectTokens("..RTE"); foreach (var rte in rtes) { var rteKind = EnumParsingSupport.ConvertFromNumericOrDefault <RteKind>(rte.SelectToken("rtekind").Value <int>()); if (rteKind == RteKind.Relation) { var relKind = EnumParsingSupport.ConvertFromStringOrDefault <RelKind>(rte.SelectToken("relkind").Value <string>()); if (relKind == RelKind.Relation) { TableInfo toAdd = new TableInfo(); toAdd.ID = rte.SelectToken("relid").Value <long>(); var table = PostgresData.Instance.PgClasses.Where(x => x.oid == toAdd.ID).First(); toAdd.Name = table.relname; var schema = PostgresData.Instance.PgNamespaces.Where(x => x.oid == table.relnamespace).First(); toAdd.SchemaName = schema.nspname; result.Add(toAdd); } } } return(result); }
private List <PredicateInfo> InitializePredicates(string qualsQuery) { List <PredicateInfo> result = new List <PredicateInfo>(); var conditions = jObject.SelectToken(qualsQuery).SelectTokens("..OPEXPR"); foreach (var condition in conditions) { PredicateInfo predicate = new PredicateInfo(); var op = predicate.Operator = new PredicateOperator(); op.ID = condition.SelectToken("opno").Value <long>(); var postgresOperator = PostgresData.Instance.PgOperators.Where(x => x.oid == op.ID).First(); op.Name = EnumParsingSupport.ConvertFromStringOrDefault <PredicateOperatorName>(postgresOperator.oprname); // todo - only bool = opresulttype == 16 (pg_type oid = 16) var constants = condition.SelectTokens("..CONST"); foreach (var c in constants) { ConstantValue cToAdd = new ConstantValue(); var constTypeOid = c.SelectToken("consttype").Value <long>(); var constValue = c.SelectToken("constvalue").Value <string>(); var postgresType = PostgresData.Instance.PgTypes.Where(x => x.oid == constTypeOid).First(); cToAdd.Type = EnumParsingSupport.ConvertFromStringOrDefault <SqlDataType>(postgresType.typname); cToAdd.Value = new ConstantValueConverter().Convert(cToAdd.Type, constValue); predicate.Operands.Add(cToAdd); } // todo vars var vars = condition.SelectTokens("..VAR"); foreach (var v in vars) { AttributeOperand toAdd = new AttributeOperand(); var rteIndex = v.SelectToken("varno").Value <int>() - 1; toAdd.Table = FromTables[rteIndex]; var typeOid = v.SelectToken("vartype").Value <long>(); var postgresType = PostgresData.Instance.PgTypes.Where(x => x.oid == typeOid).First(); toAdd.Type = EnumParsingSupport.ConvertFromStringOrDefault <SqlDataType>(postgresType.typname); var attno = v.SelectToken("varattno").Value <long>(); var postgresAttribute = PostgresData.Instance.PgAttributes.Where(x => x.attrelid == toAdd.Table.ID && x.attnum == attno).First(); toAdd.AttributeName = postgresAttribute.attname; predicate.Operands.Add(toAdd); } result.Add(predicate); } return(result); }