/* Copyright (c) Microsoft Corporation All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. */ using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Data.Linq; using System.Data.Linq.Mapping; using System.Xml; using System.Xml.Serialization; using Microsoft.Research.Dryad; namespace Microsoft.Research.Dryad.GraphManager { public class QueryPlanParser { public VertexInfo.IOType GetIoType(string type) { if (type == "File") return VertexInfo.IOType.FILELIST; if (type == "PartitionedFile") return VertexInfo.IOType.PARTITIONEDFILE; if (type == "FileDirectory") return VertexInfo.IOType.FILEDIRECTORY; if (type == "FileWildcard") return VertexInfo.IOType.FILEWILDCARD; if (type == "TidyFS") return VertexInfo.IOType.STREAM; if (type == "Dsc") return VertexInfo.IOType.STREAM; if (type == "Hdfs") return VertexInfo.IOType.HDFS_STREAM; if (type == "AzureBlob") return VertexInfo.IOType.AZUREBLOB; if (type == "FilePrefix") return VertexInfo.IOType.FILEPREFIX; throw new LinqToDryadException(String.Format("Unknown IoType: {0}", type)); } public Vertex.Type GetVertexType(string type) { if (type == "InputTable") return Vertex.Type.INPUTTABLE; if (type == "OutputTable") return Vertex.Type.OUTPUTTABLE; if (type == "Where") return Vertex.Type.WHERE; if (type == "Join") return Vertex.Type.JOIN; if (type == "Fork") return Vertex.Type.FORK; if (type == "Tee") return Vertex.Type.TEE; if (type == "Concat") return Vertex.Type.CONCAT; if (type == "Super") return Vertex.Type.SUPER; if (type == "Apply") return Vertex.Type.SUPER; return Vertex.Type.UNKNOWN; } public Predecessor.ChannelType GetChannelType(string type) { if (type == "DiskFile") return Predecessor.ChannelType.DISKFILE; if (type == "TCPPipe") return Predecessor.ChannelType.TCPPIPE; if (type == "MemoryFIFO") return Predecessor.ChannelType.MEMORYFIFO; throw new LinqToDryadException(String.Format("Unknown ChannelType: {0}", type)); } public Predecessor.ConnectionOperator GetConnectionOperator(string type) { if (type == "Pointwise") return Predecessor.ConnectionOperator.POINTWISE; if (type == "CrossProduct") return Predecessor.ConnectionOperator.CROSSPRODUCT; throw new LinqToDryadException(String.Format("Unknown ConnectionOperator: {0}", type)); } public Predecessor.AffinityConstraint GetAffinityConstraint(string type) { if (type == "UseDefault") return Predecessor.AffinityConstraint.UseDefault; if (type == "HardConstraint") return Predecessor.AffinityConstraint.HardConstraint; if (type == "OptimizationConstraint") return Predecessor.AffinityConstraint.OptimizationConstraint; if (type == "Preference") return Predecessor.AffinityConstraint.Preference; if (type == "DontCare") return Predecessor.AffinityConstraint.DontCare; throw new LinqToDryadException(String.Format("Unknown AffinityConstraint: {0}", type)); } public DynamicManager.Type GetDynamicManagerType(string type) { if (type == "None") return DynamicManager.Type.NONE; if (type == "Splitter") return DynamicManager.Type.SPLITTER; if (type == "PartialAggregator") return DynamicManager.Type.PARTIALAGGR; if (type == "FullAggregator") return DynamicManager.Type.FULLAGGR; if (type == "HashDistributor") return DynamicManager.Type.HASHDISTRIBUTOR; if (type == "RangeDistributor") return DynamicManager.Type.RANGEDISTRIBUTOR; if (type == "Broadcast") return DynamicManager.Type.BROADCAST; throw new LinqToDryadException(String.Format("Unknown DynamicManager: {0}", type)); } public static bool SplitEntryIntoAssemblyClassMethod(string entry, out string _assembly, out string _class, out string _method) { _assembly = ""; _class = ""; _method = ""; int indexBang = entry.IndexOf("!"); int indexPeriod = entry.LastIndexOf("."); if (indexBang == -1 || indexPeriod == -1 || indexPeriod <= indexBang) { return false; } _assembly = entry.Substring(0, indexBang); _class = entry.Substring(indexBang + 1, indexPeriod - indexBang - 1); _method = entry.Substring(indexPeriod + 1); return true; } private void ParseQueryXmlLinqToDryad(XmlDocument queryPlanDoc, Query query) { XmlElement root = queryPlanDoc.DocumentElement; // // Query globals // query.queryPlan = new SortedDictionary(); query.compilerversion = root.SelectSingleNode("DryadLinqVersion").InnerText; query.clusterName = root.SelectSingleNode("ClusterName").InnerText; query.visualization = root.SelectSingleNode("Visualization").InnerText; // Compression scheme for intermediate data XmlNode compressionNode = root.SelectSingleNode("IntermediateDataCompression"); if (compressionNode != null) { query.intermediateDataCompression = Convert.ToInt32(compressionNode.InnerText); } // // XmlExecHost arguments // XmlNodeList nodes = root.SelectSingleNode("XmlExecHostArgs").ChildNodes; query.xmlExecHostArgs = new string[nodes.Count]; for (int index=0; index