How to use the py4j.java_gateway.JavaClass function in py4j

To help you get started, we’ve selected a few py4j examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UCLA-VAST / blaze / spark-1.5.1 / python / pyspark / sql / types.py View on Github external
def convert(self, obj, gateway_client):
        Timestamp = JavaClass("java.sql.Timestamp", gateway_client)
        return Timestamp(int(time.mktime(obj.timetuple())) * 1000 + obj.microsecond // 1000)
github locationtech-labs / geopyspark / geopyspark / geotrellis / converters.py View on Github external
def convert(self, obj, gateway_client):
        python_extent = obj.extent
        python_tile_layout = obj.tileLayout

        ScalaExtent = JavaClass("geotrellis.vector.Extent", gateway_client)
        ScalaTileLayout = JavaClass("geotrellis.raster.TileLayout", gateway_client)
        ScalaLayoutDefinition = JavaClass("geotrellis.spark.tiling.LayoutDefinition", gateway_client)

        extent = ScalaExtent(python_extent.xmin, python_extent.ymin, python_extent.xmax, python_extent.ymax)
        tile_layout = ScalaTileLayout(python_tile_layout.layoutCols,
                                      python_tile_layout.layoutRows,
                                      python_tile_layout.tileCols,
                                      python_tile_layout.tileRows)

        return ScalaLayoutDefinition(extent, tile_layout)
github qubole / spark-on-lambda / python / pyspark / sql / types.py View on Github external
def convert(self, obj, gateway_client):
        Timestamp = JavaClass("java.sql.Timestamp", gateway_client)
        seconds = (calendar.timegm(obj.utctimetuple()) if obj.tzinfo
                   else time.mktime(obj.timetuple()))
        t = Timestamp(int(seconds) * 1000)
        t.setNanos(obj.microsecond * 1000)
        return t
github locationtech-labs / geopyspark / geopyspark / geotrellis / converters.py View on Github external
def convert(self, object, gateway_client):
        JavaRasterizerOptions = JavaClass("geotrellis.raster.rasterize.Rasterizer$Options$", gateway_client)
        if (object.sampleType == 'PixelIsPoint'):
            sample = JavaClass("geotrellis.raster.PixelIsPoint$", gateway_client)
        elif (object.sampleType == 'PixelIsArea'):
            sample = JavaClass("geotrellis.raster.PixelIsArea$", gateway_client)
        else:
            raise TypeError("Could not convert {} to geotrellis.raster.PixelSampleType".format(object.sampleType))

        sample_instance = sample.__getattr__("MODULE$")
        return JavaRasterizerOptions().apply(object.includePartial, sample_instance)
github ngageoint / mrgeo / mrgeo-python / src / main / python / pymrgeo / mapopgenerator.py View on Github external
java_import(jvm, "org.mrgeo.hdfs.utils.HadoopFileUtils")

    java_import(jvm, "org.mrgeo.data.*")

    mapops = jvm.MapOpFactory.getMapOpClasses()

    for rawmapop in mapops:
        mapop = str(rawmapop.getCanonicalName().rstrip('$'))

        # Skip IngestImageMapOp because there is an explicit method defined in
        # MrGeo class for ingesting an image, and _get_instance_type will raise
        # an exception when run against that map op.
        if not mapop.endswith(".IngestImageMapOp") and not mapop.endswith(".InlineCsvMapOp"):
            java_import(jvm, mapop)

            cls = JavaClass(mapop, gateway_client=client)

            signatures = jvm.MapOpFactory.getSignatures(mapop)
            instance = _get_instance_type(signatures, gateway, cls, mapop)
            # for s in signatures:
            #     print("signature: " + s)

            for method in cls.register():
                ooCodes = None
                procCodes = None
                if method is not None:
                    name = method.strip().lower()
                    if len(name) > 0:
                        if name in _reserved:
                            # print("reserved: " + name)
                            continue
                        elif name in _operators:
github qubole / spark-on-lambda / python / pyspark / sql / types.py View on Github external
def convert(self, obj, gateway_client):
        Date = JavaClass("java.sql.Date", gateway_client)
        return Date.valueOf(obj.strftime("%Y-%m-%d"))
github UCLA-VAST / blaze / spark-1.5.1 / python / pyspark / sql / readwriter.py View on Github external
:param url: a JDBC URL
        :param table: name of table
        :param column: the column used to partition
        :param lowerBound: the lower bound of partition column
        :param upperBound: the upper bound of the partition column
        :param numPartitions: the number of partitions
        :param predicates: a list of expressions
        :param properties: JDBC database connection arguments, a list of arbitrary string
                           tag/value. Normally at least a "user" and "password" property
                           should be included.
        :return: a DataFrame
        """
        if properties is None:
            properties = dict()
        jprop = JavaClass("java.util.Properties", self._sqlContext._sc._gateway._gateway_client)()
        for k in properties:
            jprop.setProperty(k, properties[k])
        if column is not None:
            if numPartitions is None:
                numPartitions = self._sqlContext._sc.defaultParallelism
            return self._df(self._jreader.jdbc(url, table, column, int(lowerBound), int(upperBound),
                                               int(numPartitions), jprop))
        if predicates is not None:
            arr = self._sqlContext._sc._jvm.PythonUtils.toArray(predicates)
            return self._df(self._jreader.jdbc(url, table, arr, jprop))
        return self._df(self._jreader.jdbc(url, table, jprop))
github apache / flink / flink-python / pyflink / table / types.py View on Github external
def _is_instance_of(java_data_type, java_class):
    gateway = get_gateway()
    if isinstance(java_class, str):
        param = java_class
    elif isinstance(java_class, JavaClass):
        param = get_java_class(java_class)
    elif isinstance(java_class, JavaObject):
        if not _is_instance_of(java_class, gateway.jvm.Class):
            param = java_class.getClass()
        else:
            param = java_class
    else:
        raise TypeError(
            "java_class must be a string, a JavaClass, or a JavaObject")

    return gateway.jvm.org.apache.flink.api.python.shaded.py4j.reflection.TypeUtil.isInstanceOf(
        param, java_data_type)
github locationtech-labs / geopyspark / geopyspark / geotrellis / converters.py View on Github external
def convert(self, obj, gateway_client):
        name = obj.value

        if name == 'NearestNeighbor':
            sample = JavaClass("geotrellis.raster.resample.NearestNeighbor$", gateway_client)
        elif name == 'Bilinear':
            sample = JavaClass("geotrellis.raster.resample.Bilinear$", gateway_client)
        elif name == 'CubicConvolution':
            sample = JavaClass("geotrellis.raster.resample.CubicConvolution$", gateway_client)
        elif name == 'CubicSpline':
            sample = JavaClass("geotrellis.raster.resample.CubicSpline$", gateway_client)
        elif name == 'Lanczos':
            sample = JavaClass("geotrellis.raster.resample.Lanczos$", gateway_client)
        elif name == 'Average':
            sample = JavaClass("geotrellis.raster.resample.Average$", gateway_client)
        elif name == 'Mode':
            sample = JavaClass("geotrellis.raster.resample.Mode$", gateway_client)
        elif name == 'Median':
            sample = JavaClass("geotrellis.raster.resample.Median$", gateway_client)
        elif name == 'Max':
            sample = JavaClass("geotrellis.raster.resample.Max$", gateway_client)
        elif name == 'Min':
            sample = JavaClass("geotrellis.raster.resample.Min$", gateway_client)
        else:
            raise TypeError(name, "Could not be converted to a GeoTrellis ResampleMethod.")
github locationtech-labs / geopyspark / geopyspark / geotrellis / converters.py View on Github external
if name == 'NearestNeighbor':
            sample = JavaClass("geotrellis.raster.resample.NearestNeighbor$", gateway_client)
        elif name == 'Bilinear':
            sample = JavaClass("geotrellis.raster.resample.Bilinear$", gateway_client)
        elif name == 'CubicConvolution':
            sample = JavaClass("geotrellis.raster.resample.CubicConvolution$", gateway_client)
        elif name == 'CubicSpline':
            sample = JavaClass("geotrellis.raster.resample.CubicSpline$", gateway_client)
        elif name == 'Lanczos':
            sample = JavaClass("geotrellis.raster.resample.Lanczos$", gateway_client)
        elif name == 'Average':
            sample = JavaClass("geotrellis.raster.resample.Average$", gateway_client)
        elif name == 'Mode':
            sample = JavaClass("geotrellis.raster.resample.Mode$", gateway_client)
        elif name == 'Median':
            sample = JavaClass("geotrellis.raster.resample.Median$", gateway_client)
        elif name == 'Max':
            sample = JavaClass("geotrellis.raster.resample.Max$", gateway_client)
        elif name == 'Min':
            sample = JavaClass("geotrellis.raster.resample.Min$", gateway_client)
        else:
            raise TypeError(name, "Could not be converted to a GeoTrellis ResampleMethod.")

        return sample.__getattr__("MODULE$")