コード例 #1
0
ファイル: RawRecord.cs プロジェクト: blinds52/nhind
        /// <summary>
        /// Compares a Raw Record to this given resource record
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public override bool Equals(DnsResourceRecord record)
        {
            if (!base.Equals(record))
            {
                return(false);
            }

            RawRecord rawRecord = record as RawRecord;

            if (rawRecord == null)
            {
                return(false);
            }

            if (rawRecord.m_bytes.Length != m_bytes.Length)
            {
                return(false);
            }

            for (int i = 0; i < m_bytes.Length; ++i)
            {
                if (m_bytes[i] != rawRecord.m_bytes[i])
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
ファイル: InitialProcessor.cs プロジェクト: httpv3/QuicDotNet
 public async Task Run()
 {
     await foreach (var record in RawRecord.ReadRecords(conn, stream.Input, conn.cancel))
     {
         await Process(record);
     }
 }
コード例 #3
0
        public void EnsureEntityIsCreatedEvenFlushedWithoutTransaction()
        {
            using (Transaction.Begin())
            {
                Transaction.RunningTransaction.Run("CREATE (n:SampleEntity { name: 'Address', title: 'Developer' })");
                RawResult result = Transaction.RunningTransaction.Run("Match (n:SampleEntity) Return n");
                RawRecord record = result.FirstOrDefault();

                RawNode loaded = record["n"].As <RawNode>();
                Assert.AreEqual(loaded.Properties["name"], "Address");
                Assert.AreEqual(loaded.Properties["title"], "Developer");

                Transaction.Flush();
            }

            using (Transaction.Begin())
            {
                RawResult result = Transaction.RunningTransaction.Run("Match (n:SampleEntity) Return n");
                RawRecord record = result.FirstOrDefault();

                RawNode loaded = record["n"].As <RawNode>();
                Assert.AreEqual(loaded.Properties["name"], "Address");
                Assert.AreEqual(loaded.Properties["title"], "Developer");
            }
        }
コード例 #4
0
        public FeatureValue Compress(
            IList <FeatureValue> values, RawRecord record,
            FeatureGroup featureGroup, FeatureSelectionContext context)
        {
            var scalarProduct = 0.0d;
            var vectorXNorm   = 0.0d;
            var vectorYNorm   = 0.0d;

            for (var i = 0; i < values.Count; i++)
            {
                scalarProduct += values[i].NumericValue;
                vectorXNorm   += Math.Pow(values[i].NumericValue, 2);
                vectorYNorm   += 1;
            }

            if (vectorXNorm == 0)
            {
                return(new FeatureValue(0));
            }

            vectorXNorm = Math.Sqrt(vectorXNorm);
            vectorYNorm = Math.Sqrt(vectorYNorm);

            return(new FeatureValue((float)(scalarProduct / (vectorXNorm * vectorYNorm))));
        }
コード例 #5
0
        public override RawRecord Next()
        {
            if (this.inputOp.State())
            {
                RawRecord r = this.inputOp.Next();
                if (r == null)
                {
                    this.Close();
                    return(null);
                }

                CollectionField path = r[this.pathIndex] as CollectionField;

                Debug.Assert(path != null);

                this.TreeState.Accumulate(path);

                if (!this.inputOp.State())
                {
                    this.Close();
                }
                return(r);
            }

            return(null);
        }
コード例 #6
0
        protected virtual void Initialize(RawRecord record)
        {
            Name        = record.Values["description"].As <string>();
            IsUnique    = false;
            IsMandatory = false;

            Match uniqueMatch  = UniqueMatch(Name);
            Match notnullMatch = NotNullMatch(Name);

            if (!uniqueMatch.Success && !notnullMatch.Success)
            {
                throw new NotSupportedException("One of the two regular expressions should produce a match...");
            }

            if (uniqueMatch.Success)
            {
                Entity   = uniqueMatch.Groups["entity"].Value;
                Field    = uniqueMatch.Groups["field"].Value;
                IsUnique = true;
            }
            if (notnullMatch.Success)
            {
                Entity      = notnullMatch.Groups["entity"].Value;
                Field       = notnullMatch.Groups["field"].Value;
                IsMandatory = true;
            }
        }
コード例 #7
0
 protected virtual void Initialize(RawRecord record)
 {
     Label          = record.Values["Label"].As <string>();
     Prefix         = record.Values["Prefix"].As <string>();
     SequenceNumber = (int)record.Values["Sequence"].As <long>();
     SequenceHash   = record.Values["Uid"].As <string>();
 }
コード例 #8
0
ファイル: TVFOperator.cs プロジェクト: georgeycliu/k-core
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            List <RawRecord> results = new List <RawRecord>();

            FieldObject target = record[this._targetIndex];

            if (target != null)
            {
                VertexField vertex = target as VertexField;
                if (vertex != null)
                {
                    RawRecord r = new RawRecord();
                    r.Append(new StringField(vertex.VertexMetaProperties[KW_DOC_ID].ToValue));
                    results.Add(r);
                }

                VertexSinglePropertyField vertexSingleProperty = target as VertexSinglePropertyField;
                if (vertexSingleProperty != null)
                {
                    RawRecord r = new RawRecord();
                    r.Append(new StringField(vertexSingleProperty.PropertyId));
                    results.Add(r);
                }

                EdgeField edge = target as EdgeField;
                if (edge != null)
                {
                    RawRecord r = new RawRecord();
                    r.Append(new StringField(edge.EdgeId));
                    results.Add(r);
                }
            }

            return(results);
        }
コード例 #9
0
        // for each of the input records,
        //  if it satisfy the until condition
        //  then enqueue it to repeatResultBuffer
        //  else keep it for next loop
        private List <RawRecord> Until(List <RawRecord> records)
        {
            // when query has no .until() (neither .times())
            if (this.untilCondition == null)
            {
                return(records);
            }

            List <RawRecord> batchRecords = new List <RawRecord>();

            foreach (RawRecord record in records)
            {
                RawRecord batchRecord = new RawRecord();
                batchRecord.Append(new StringField(batchRecords.Count.ToString(), JsonDataType.Int));
                batchRecord.Append(record);
                batchRecords.Add(batchRecord);
            }

            HashSet <int> haveOutput = this.untilCondition.EvaluateInBatch(batchRecords);

            haveOutput.Select(x => records[x]).ToList().ForEach(this.repeatResultBuffer.Enqueue);

            List <RawRecord> result = new List <RawRecord>();

            batchRecords.ForEach(x => {
                if (!haveOutput.Contains(int.Parse(x.RetriveData(0).ToValue)))
                {
                    result.Add(x.GetRange(1));
                }
            });
            return(result);
        }
コード例 #10
0
        public override RawRecord Next()
        {
            if (inputOp.State())
            {
                RawRecord r = inputOp.Next();
                if (r == null)
                {
                    Close();
                    return(null);
                }

                FieldObject groupByKey = groupByKeyFieldIndex >= 0
                    ? new StringField(r[groupByKeyFieldIndex].ToValue)
                    : groupByKeyFunction.Evaluate(r);

                GroupState.Accumulate(new Object[] { groupByKey, r });

                if (!inputOp.State())
                {
                    Close();
                }
                return(r);
            }

            return(null);
        }
コード例 #11
0
        public override RawRecord Next()
        {
            if (this.inputOp != null && this.inputOp.State())
            {
                List <RawRecord> inputRecords = new List <RawRecord>();
                RawRecord        inputRec;
                while (this.inputOp.State() && (inputRec = this.inputOp.Next()) != null)
                {
                    inputRecords.Add(inputRec);
                }

                this.container.ResetTableCache(inputRecords);
            }

            RawRecord derivedRecord;

            while (this.derivedQueryOp.State() && (derivedRecord = this.derivedQueryOp.Next()) != null)
            {
                RawRecord returnRecord = new RawRecord();
                for (int i = 0; i < this.carryOnCount; i++)
                {
                    returnRecord.Append((FieldObject)null);
                }

                returnRecord.Append(derivedRecord);
                return(returnRecord);
            }

            this.Close();
            return(null);
        }
コード例 #12
0
        public FeatureValue Compress(
            IList <FeatureValue> values, RawRecord record,
            FeatureGroup featureGroup, FeatureSelectionContext context)
        {
            context.Project.PluginData
            .GetData <LoggingPlugin, UsageStatistics>(string.Empty)
            .CosThetaUnitaryCounter++;

            var scalarProduct = 0.0d;
            var vectorXNorm   = 0.0d;
            var vectorYNorm   = 0.0d;

            for (var i = 0; i < values.Count; i++)
            {
                scalarProduct += values[i].NumericValue;
                vectorXNorm   += Math.Pow(values[i].NumericValue, 2);
                vectorYNorm   += 1;
            }

            if (vectorXNorm == 0)
            {
                return(new FeatureValue(0));
            }

            vectorXNorm = Math.Sqrt(vectorXNorm);
            vectorYNorm = Math.Sqrt(vectorYNorm);

            return(new FeatureValue((float)(scalarProduct / (vectorXNorm * vectorYNorm))));
        }
コード例 #13
0
        internal override RawRecord DataModify(RawRecord record)
        {
            JObject vertexObject = this._vertexDocument;

            string vertexId = GraphViewConnection.GenerateDocumentId();

            Debug.Assert(vertexObject["id"] == null);
            Debug.Assert(vertexObject["_partition"] == null);
            vertexObject["id"]         = vertexId;
            vertexObject["_partition"] = vertexId;

            this.Connection.CreateDocumentAsync(vertexObject).Wait();

            VertexField vertexField = Connection.VertexCache.GetVertexField(vertexId, vertexObject);

            RawRecord result = new RawRecord();

            foreach (string fieldName in _projectedFieldList)
            {
                FieldObject fieldValue = vertexField[fieldName];

                result.Append(fieldValue);
            }

            return(result);
        }
コード例 #14
0
ファイル: TVFOperator.cs プロジェクト: georgeycliu/k-core
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            RawRecord result = new RawRecord();

            if (this.constantValues.Count == 0 && !this.isList)
            {
                return(new List <RawRecord>());
            }

            if (isList)
            {
                List <FieldObject> collection = new List <FieldObject>();
                foreach (ScalarFunction constantValueFunc in this.constantValues)
                {
                    Dictionary <string, FieldObject> compositeFieldObjects = new Dictionary <string, FieldObject>();
                    compositeFieldObjects.Add(defaultProjectionKey, constantValueFunc.Evaluate(null));
                    collection.Add(new Compose1Field(compositeFieldObjects, defaultProjectionKey));
                }
                result.Append(new CollectionField(collection));
            }
            else
            {
                result.Append(this.constantValues[0].Evaluate(null));
            }

            return(new List <RawRecord> {
                result
            });
        }
コード例 #15
0
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            RawRecord result = new RawRecord();

            if (this.constantValues.Count == 0 && !this.isList)
            {
                return(new List <RawRecord>());
            }

            if (isList)
            {
                List <FieldObject> collection = new List <FieldObject>();
                foreach (ScalarFunction constantValueFunc in this.constantValues)
                {
                    collection.Add(constantValueFunc.Evaluate(null));
                }
                result.Append(new CollectionField(collection));
            }
            else
            {
                result.Append(this.constantValues[0].Evaluate(null));
            }

            return(new List <RawRecord> {
                result
            });
        }
コード例 #16
0
        protected virtual void Initialize(RawRecord record)
        {
            Description = record.Values["description"].As <string>();
            State       = record.Values["state"].As <string>();
            Type        = record.Values["type"].As <string>();
            IsIndexed   = true;

            switch (Type.ToLowerInvariant().Trim())
            {
            case "node_unique_property":
                isUnique = true;
                break;

            case "node_label_property":
                isUnique = false;
                break;

            default:
                throw new NotSupportedException("There should be no unknown types of indexes");
            }

            Match results = index.Match(Description);

            if (!results.Success)
            {
                throw new NotSupportedException("The regular expression should always produce a match...");
            }

            Entity = results.Groups["entity"].Value;
            Field  = results.Groups["field"].Value;
        }
コード例 #17
0
        public override RawRecord Next()
        {
            if (this.inputOp.State())
            {
                RawRecord r = this.inputOp.Next();
                if (r == null)
                {
                    this.Close();
                    return(null);
                }

                FieldObject groupByKey = this.groupByKeyFunction.Evaluate(r);

                if (groupByKey == null)
                {
                    throw new GraphViewException("The provided property name or traversal does not map to a value for some elements.");
                }

                this.GroupState.Accumulate(new Object[] { groupByKey, r });

                if (!this.inputOp.State())
                {
                    this.Close();
                }
                return(r);
            }

            return(null);
        }
コード例 #18
0
ファイル: GraphTraversal2.cs プロジェクト: georgeycliu/k-core
        public List <string> Next()
        {
            WSqlScript sqlScript = this.GetEndOp().ToSqlScript();

            SqlScript = sqlScript.ToString();

            GraphViewExecutionOperator op = sqlScript.Batches[0].Compile(null, this.connection);
            List <RawRecord>           rawRecordResults = new List <RawRecord>();
            RawRecord outputRec = null;

            while ((outputRec = op.Next()) != null)
            {
                rawRecordResults.Add(outputRec);
            }

            List <string> results = new List <string>();

            switch (outputFormat)
            {
            case OutputFormat.GraphSON:
                results.Add(GraphSONProjector.ToGraphSON(rawRecordResults, this.connection));
                break;

            default:
                foreach (var record in rawRecordResults)
                {
                    FieldObject field = record[0];
                    results.Add(field.ToString());
                }
                break;
            }

            return(results);
        }
コード例 #19
0
        public override FieldObject Evaluate(RawRecord record)
        {
            FieldObject     checkObject = record[_checkFieldIndex];
            CollectionField arrayObject = record[_arrayFieldIndex] as CollectionField;

            if (arrayObject == null)
            {
                throw new GraphViewException("The second paramter of the WithInArray function must be located to a collection field");
            }
            if (checkObject == null)
            {
                return(new StringField("false", JsonDataType.Boolean));
            }

            foreach (FieldObject fieldObject in arrayObject.Collection)
            {
                if (fieldObject is Compose1Field)
                {
                    Compose1Field compose1Field = fieldObject as Compose1Field;
                    if (checkObject.Equals(compose1Field.Map[compose1Field.DefaultProjectionKey]))
                    {
                        return(new StringField("true", JsonDataType.Boolean));
                    }
                }
                else if (checkObject.Equals(fieldObject))
                {
                    return(new StringField("true", JsonDataType.Boolean));
                }
            }

            return(new StringField("false", JsonDataType.Boolean));
        }
コード例 #20
0
        internal object GetRawRecordInstance(RawRecord record)
        {
            var structureType = ManagedStructureTypes[record.StructureIndex];
            var instance      = ManagedDataTable[structureType][record.VariantIndex];

            return(instance);
        }
コード例 #21
0
        public override RawRecord Next()
        {
            RawRecord srcRecord = null;

            while (InputOperator.State() && (srcRecord = InputOperator.Next()) != null)
            {
                RawRecord result = DataModify(srcRecord);
                if (result == null)
                {
                    continue;
                }

                //foreach (var tuple in PropertiesToBeUpdated)
                //{
                //    var propertyIndex = tuple.Item3;
                //    var propertyNewValue = tuple.Item2;
                //    if (propertyIndex == -1) continue;

                //    srcRecord.fieldValues[propertyIndex] = new StringField(propertyNewValue.Value);
                //}

                return(srcRecord);
            }

            Close();
            return(null);
        }
コード例 #22
0
 public override void ResetState()
 {
     currentRecord = null;
     inputOperator.ResetState();
     outputBuffer.Clear();
     this.Open();
 }
コード例 #23
0
        public FeatureValue Compress(
            IList <FeatureValue> values, RawRecord record,
            FeatureGroup featureGroup, FeatureSelectionContext context)
        {
            var vectorX = values;
            var vectorY = new List <FeatureValue>(values.Count);

            for (var i = 0; i < featureGroup.CompressionElements.Count; i++)
            {
                var featureValues = featureGroup.CompressionElements[i].GetValues(record, context);

                for (var j = 0; j < featureValues.Count; j++)
                {
                    vectorY.Add(featureValues[j]);
                }
            }

            if (vectorX.Count < vectorY.Count)
            {
                vectorX = vectorX.ToList();

                var missingCount = vectorY.Count - vectorX.Count;

                for (var i = 0; i < missingCount; i++)
                {
                    vectorX.Add(new FeatureValue(0));
                }
            }
            else if (vectorY.Count < vectorX.Count)
            {
                var missingCount = vectorX.Count - vectorY.Count;

                for (var i = 0; i < missingCount; i++)
                {
                    vectorY.Add(new FeatureValue(0));
                }
            }

            var scalarProduct = 0.0d;
            var vectorXNorm   = 0.0d;
            var vectorYNorm   = 0.0d;

            for (var i = 0; i < vectorX.Count; i++)
            {
                scalarProduct += vectorX[i].NumericValue * vectorY[i].NumericValue;
                vectorXNorm   += Math.Pow(vectorX[i].NumericValue, 2);
                vectorYNorm   += Math.Pow(vectorY[i].NumericValue, 2);
            }

            if (vectorXNorm == 0 || vectorYNorm == 0)
            {
                return(new FeatureValue(0));
            }

            vectorXNorm = Math.Sqrt(vectorXNorm);
            vectorYNorm = Math.Sqrt(vectorYNorm);

            return(new FeatureValue((float)(scalarProduct / (vectorXNorm * vectorYNorm))));
        }
コード例 #24
0
ファイル: ScalarFunction.cs プロジェクト: seanliu96/GraphView
 public override FieldObject Evaluate(RawRecord record)
 {
     if (this.dataType == JsonDataType.Null)
     {
         return(null);
     }
     return(new StringField(value, dataType));
 }
コード例 #25
0
        public void RawRecord_EncodeRecord_1()
        {
            string[]  lines   = _GetLines();
            RawRecord record  = RawRecord.Parse(lines);
            string    encoded = record.EncodeRecord();

            Assert.IsNotNull(encoded);
        }
コード例 #26
0
        public void RawRecord_Parse_2()
        {
            string[]  lines  = _GetLines();
            RawRecord record = RawRecord.Parse(lines);

            Assert.AreEqual(154569, record.Mfn);
            Assert.AreEqual(22, record.Lines.Length);
        }
コード例 #27
0
 internal DataCoreRecord(DataCoreDatabase database, RawRecord record)
 {
     ID            = record.ID;
     Name          = database.RawDatabase.textBlock.GetString(record.NameOffset);
     FileName      = database.RawDatabase.textBlock.GetString(record.FileNameOffset);
     StructureType = database.ManagedStructureTypes[record.StructureIndex];
     Instance      = database.GetRawRecordInstance(record);
 }
コード例 #28
0
        public virtual void ResetTableCache(RawRecord record)
        {
            Debug.Assert(record != null);

            this.tableCache = new List <RawRecord> {
                record
            };
        }
コード例 #29
0
        public FieldObject Terminate()
        {
            MapField result = new MapField();

            if (this.isProjectingACollection)
            {
                foreach (FieldObject key in groupedStates.Keys)
                {
                    List <FieldObject> projectFields = new List <FieldObject>();
                    foreach (RawRecord rawRecord in groupedStates[key])
                    {
                        this.groupedSourceOp.ResetState();
                        this.aggregateOp.ResetState();
                        this.tempSourceOp.ConstantSource = rawRecord;
                        this.groupedSourceOp.Next();

                        RawRecord   aggregateTraversalRecord = this.aggregateOp.Next();
                        FieldObject projectResult            = aggregateTraversalRecord?.RetriveData(0);

                        if (projectResult == null)
                        {
                            throw new GraphViewException("The property does not exist for some of the elements having been grouped.");
                        }

                        projectFields.Add(projectResult);
                    }
                    result[key] = new CollectionField(projectFields);
                }
            }
            else
            {
                foreach (KeyValuePair <FieldObject, List <RawRecord> > pair in this.groupedStates)
                {
                    FieldObject      key = pair.Key;
                    List <RawRecord> aggregatedRecords = pair.Value;
                    this.groupedSourceOp.ResetState();
                    this.aggregateOp.ResetState();

                    foreach (RawRecord record in aggregatedRecords)
                    {
                        this.tempSourceOp.ConstantSource = record;
                        this.groupedSourceOp.Next();
                    }

                    RawRecord aggregateTraversalRecord = this.aggregateOp.Next();

                    FieldObject aggregateResult = aggregateTraversalRecord?.RetriveData(0);
                    if (aggregateResult == null)
                    {
                        return(null);
                    }

                    result[key] = aggregateResult;
                }
            }

            return(result);
        }
コード例 #30
0
ファイル: RawColumnParser.cs プロジェクト: ycherkes/OrcaSql
 public static dynamic Parse(RawRecord record, IRawType[] schema)
 {
     return(Parse(
                record.FixedLengthData != null ? record.FixedLengthData.ToArray() : null,
                record.VariableLengthOffsetValues != null ? record.VariableLengthOffsetValues.Select(x => x.ToArray()).ToArray() : null,
                record.NullBitmapRawBytes != null ? record.NullBitmapRawBytes.ToArray() : new byte[0],
                schema
                ));
 }