|
| 1 | +import semantic_version |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import matplotlib.patches as patches |
| 4 | + |
| 5 | +meta_to_query_compat = [ |
| 6 | + # upto meta version(exclusive) : compatible query version(left open, right closed) |
| 7 | + |
| 8 | + "0.0.0 0.0.0 0.0.0 ", |
| 9 | + "0.8.30 0.0.0 0.0.0 ", |
| 10 | + "0.8.35 0.7.59 0.8.80 ", |
| 11 | + "0.9.23 0.7.59 1.1.34 ", |
| 12 | + "0.9.42 0.8.80 1.1.34 ", |
| 13 | + "1.1.32 0.9.41 1.1.34 ", |
| 14 | + "1.2.226 0.9.41 1.2.287 ", |
| 15 | + "1.2.258 0.9.41 1.2.361 ", |
| 16 | + "1.2.663 0.9.41 1.2.726 ", |
| 17 | + "1.2.677 1.2.287 1.2.726 ", |
| 18 | + "1.2.755 1.2.676 ∞ ", |
| 19 | + "1.2.756 1.2.676 ∞ ", |
| 20 | + "1.2.764 1.2.676 ∞ ", |
| 21 | + "∞ 1.2.676 ∞ ", |
| 22 | +] |
| 23 | + |
| 24 | +def draw_meta_to_query_compat(output_file: str): |
| 25 | + fig, ax = plt.subplots(figsize=(12, 8)) |
| 26 | + |
| 27 | + # Parse compatibility data and collect all unique versions |
| 28 | + ranges = [] |
| 29 | + all_meta_versions = set() |
| 30 | + all_query_versions = set() |
| 31 | + |
| 32 | + for i, line in enumerate(meta_to_query_compat): |
| 33 | + if line.strip(): |
| 34 | + meta, q_from, q_to = line.strip().split() |
| 35 | + |
| 36 | + # Skip empty ranges |
| 37 | + if q_from == "0.0.0" and q_to == "0.0.0": |
| 38 | + continue |
| 39 | + |
| 40 | + ranges.append((meta, q_from, q_to)) |
| 41 | + all_meta_versions.add(meta) |
| 42 | + all_query_versions.add(q_from) |
| 43 | + all_query_versions.add(q_to) |
| 44 | + |
| 45 | + # Sort versions and create position mappings |
| 46 | + def version_key(v): |
| 47 | + if v == "∞": |
| 48 | + return (999, 999, 999) |
| 49 | + ver = semantic_version.Version(v) |
| 50 | + return (ver.major, ver.minor, ver.patch) |
| 51 | + |
| 52 | + sorted_meta_versions = sorted(all_meta_versions, key=version_key) |
| 53 | + sorted_query_versions = sorted(all_query_versions, key=version_key) |
| 54 | + |
| 55 | + # Create position mappings |
| 56 | + meta_pos = {v: i for i, v in enumerate(sorted_meta_versions)} |
| 57 | + query_pos = {v: i for i, v in enumerate(sorted_query_versions)} |
| 58 | + |
| 59 | + # Create compatibility rectangles |
| 60 | + for i, (meta, q_from, q_to) in enumerate(ranges): |
| 61 | + # Get positions |
| 62 | + meta_x = meta_pos[meta] |
| 63 | + q_from_y = query_pos[q_from] |
| 64 | + q_to_y = query_pos[q_to] |
| 65 | + |
| 66 | + # Determine the width of the rectangle (next meta version - current) |
| 67 | + next_meta_idx = sorted_meta_versions.index(meta) + 1 |
| 68 | + if next_meta_idx < len(sorted_meta_versions): |
| 69 | + width = meta_pos[sorted_meta_versions[next_meta_idx]] - meta_x |
| 70 | + else: |
| 71 | + width = 1.0 # Width for the last range |
| 72 | + |
| 73 | + # Height of the rectangle |
| 74 | + height = q_to_y - q_from_y |
| 75 | + |
| 76 | + # Create rectangle patch |
| 77 | + rect = patches.Rectangle( |
| 78 | + (meta_x, q_from_y), |
| 79 | + width, |
| 80 | + height, |
| 81 | + linewidth=1, |
| 82 | + edgecolor='darkgreen', |
| 83 | + facecolor='lightgreen', |
| 84 | + alpha=0.7 |
| 85 | + ) |
| 86 | + ax.add_patch(rect) |
| 87 | + |
| 88 | + # Set up the plot |
| 89 | + ax.set_xlim(-0.5, len(sorted_meta_versions) - 0.5) |
| 90 | + ax.set_ylim(-0.5, len(sorted_query_versions) - 0.5) |
| 91 | + ax.set_xlabel('Meta Version', fontsize=12, fontweight='bold') |
| 92 | + ax.set_ylabel('Compatible With Query', fontsize=12, fontweight='bold') |
| 93 | + ax.set_title('Databend-Meta/Query Version Compatibility Chart', fontsize=14, fontweight='bold') |
| 94 | + |
| 95 | + # Add grid |
| 96 | + ax.grid(True, alpha=0.3) |
| 97 | + |
| 98 | + # Set ticks with version labels |
| 99 | + ax.set_xticks(range(len(sorted_meta_versions))) |
| 100 | + ax.set_xticklabels([v if v != "∞" else "+∞" for v in sorted_meta_versions], rotation=45) |
| 101 | + |
| 102 | + ax.set_yticks(range(len(sorted_query_versions))) |
| 103 | + ax.set_yticklabels([v if v != "∞" else "+∞" for v in sorted_query_versions]) |
| 104 | + |
| 105 | + # Add legend |
| 106 | + legend_patch = patches.Patch(color='lightgreen', label='Compatible Query Versions') |
| 107 | + ax.legend(handles=[legend_patch], loc='upper left') |
| 108 | + |
| 109 | + # Save the plot |
| 110 | + plt.tight_layout() |
| 111 | + plt.savefig(output_file, dpi=300, bbox_inches='tight') |
| 112 | + plt.close() |
| 113 | + |
| 114 | + print(f"Compatibility chart saved to {output_file}") |
| 115 | + |
| 116 | + |
| 117 | +if __name__ == "__main__": |
| 118 | + output_file = "compatibility_chart.png" |
| 119 | + draw_meta_to_query_compat(output_file) |
| 120 | + print(f"Chart generated: {output_file}") |
| 121 | + |
| 122 | + |
| 123 | + |
0 commit comments