Skip to content

Commit

Permalink
Merge pull request #7 from dogversioning/main
Browse files Browse the repository at this point in the history
Added python parquet tools, Sublime v3/4 updates
  • Loading branch information
yuj authored Dec 6, 2022
2 parents 7b82ece + 98128cb commit cde6176
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 63 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.git* export-ignore
/data export-ignore
screencap.png export-ignore
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@ ENV/
.ropeproject

# IDE
.idea
.idea

#sample data
.parquet
.csv

#input testing
data/
53 changes: 0 additions & 53 deletions Parquet.py

This file was deleted.

14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# sublime-parquet
Reads Apache Parquet files in Sublime Text. The records are shown in JSON format, one JSON object per line. Parquet files are opened in read-only mode.
Reads Apache Parquet files in Sublime Text using they python parquet-tools package. Files are rendered as CSVs.

# Screenshot
![screenshot](https://raw.github.com/yuj/sublime-parquet/master/screenshot.png)
![screencap](https://raw.github.com/dogversioning/sublime-parquet-python/main/screencap.png)

# Installation
**via Package Control**

1. Make sure you have [Package Control](https://packagecontrol.io/installation) installed.
1. Open the Command Palette (`command-shift-P` on macOS; `ctrl-shift-P` on Ubuntu) and choose _Install Package_.
1. Open the Command Palette (`command-shift-P` on macOS; `ctrl-shift-P` on Ubuntu/Windows) and choose _Install Package_.
1. Choose _Parquet_ from the list.

# Requirement
This sublime package depends on the [parquet-tools](https://github.com/apache/parquet-mr/tree/master/parquet-tools) software. Make sure it is installed and on your PATH.

On macOS (or Ubuntu), run ```brew install parquet-tools```.

To install brew, visit http://brew.sh.
# Requirements

You'll need to have a python environment in your path, and then install [parquet-tools](https://github.com/ktrueda/parquet-tools) with `pip install parquet-tools`.
58 changes: 58 additions & 0 deletions parquet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-

import sublime
import sublime_plugin

import os
import subprocess


"""
Parquet package for Sublime Text, with python tooling.
https://github.com/yuj/sublime-parquet
Requires the python port of parquet-tools
https://github.com/ktrueda/parquet-tools
"""


COMMAND_NOT_FOUND_MSG = """'parquet-tools' not found.\n
Make sure python is in your PATH and install with 'pip install parquet-tools'
"""
PYTHON_COMMAND_LINE = "parquet-tools csv {0}"
UNICODE_ERROR = "Non-unicode characters prevented rendering: \n"


def run_command(command):
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return iter(p.stdout.readline, b"")


class ParquetCommand(sublime_plugin.TextCommand):
def run(self, edit, filename=None):
if filename is None or not filename.endswith(".parquet"):
return
command = PYTHON_COMMAND_LINE.format('"' + filename + '"')
pos = 0
try:
for line in run_command(command):
row = line.decode("utf-8")
pos += self.view.insert(edit, pos, row.rstrip() + "\n")
except (UnicodeDecodeError, TypeError):
self.view.set_name(os.path.basename(filename))
self.view.set_read_only(True)
sublime.error_message(UNICODE_ERROR + str(line))
except (FileNotFoundError, AttributeError):
sublime.error_message(COMMAND_NOT_FOUND_MSG)
self.view.set_name(os.path.basename(filename))
self.view.set_read_only(True)


class OpenParquetFile(sublime_plugin.EventListener):
def on_load(self, view):
filename = view.file_name()
if filename.endswith(".parquet"):
sublime.status_message("opening parquet file: " + filename)
parquet_view = view.window().new_file()
view.close()
parquet_view.run_command("parquet", {"filename": filename})
Binary file added screencap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshot.png
Binary file not shown.

0 comments on commit cde6176

Please sign in to comment.