Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic array deserialization of atomics (#456) #457

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Build'

env:
VERSION: 4.22.0
VERSION: 4.22.1
ASM_VERSION: 4.0.0
DOC_INSTANCE: wrs/pq
DOC_ARTIFACT: webHelpPQ2-all.zip
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ jobs:
bin/*.nupkg
floor/*.zip
body_path: release-notes.md
discussion_category_name: announcements
12 changes: 12 additions & 0 deletions docs/release-history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 4.22.1

### Improvements

- Deserialization into array of primitives is now supported on root class level in #456.
- Untyped deserialiser supports legacy arrays.

### Parquet Floor

- Schema will still be loaded even if a file has failed to load.
- Legacy arrays can be viewed.

## 4.22.0

### Improvements
Expand Down
Binary file removed src/Parquet.Floor/Assets/icons/bat_dead.png
Binary file not shown.
1 change: 0 additions & 1 deletion src/Parquet.Floor/Parquet.Floor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

<ItemGroup>
<None Remove="Assets\icon.ico" />
<None Remove="Assets\icons\bat_dead.png" />
</ItemGroup>


Expand Down
2 changes: 1 addition & 1 deletion src/Parquet.Floor/Parquet.Floor.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>clean</ActiveDebugProfile>
<ActiveDebugProfile>fail</ActiveDebugProfile>
</PropertyGroup>
</Project>
21 changes: 0 additions & 21 deletions src/Parquet.Floor/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@

</Expander>

<Grid Classes="error">
<StackPanel>
<Image Source="/Assets/icons/bat_dead.png"/>
<TextBlock Text="design time error message" />
</StackPanel>
</Grid>

<Image Source="/Assets/icons/col/string.png" Classes="dt-icon"/>

Expand Down Expand Up @@ -131,21 +125,6 @@
<Setter Property="FontWeight" Value="Bold"/>
</Style>

<!-- error message -->

<Style Selector="Grid.error">
<Setter Property="Background" Value="{DynamicResource SystemControlBackgroundChromeMediumBrush}"/>
</Style>

<Style Selector="Grid.error Image">
<Setter Property="Width" Value="40"/>
</Style>

<Style Selector="Grid.error TextBlock.error">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>

<!-- raw meta -->
<Style Selector="StackPanel.raw-meta-section StackPanel">
<Setter Property="Margin" Value="4"/>
Expand Down
37 changes: 31 additions & 6 deletions src/Parquet.Floor/ViewModels/DataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public partial class DataViewModel : ViewModelBase {
[ObservableProperty]
private IList<Dictionary<string, object>>? _data;

[ObservableProperty]
private bool _hasError;

[ObservableProperty]
private string? _errorMessage;

[ObservableProperty]
private string? _errorDetails;

[ObservableProperty]
private bool _showErrorDetails;

public DataViewModel() {
#if DEBUG
if(Design.IsDesignMode) {
Expand All @@ -43,15 +55,28 @@ public DataViewModel() {
}

public async Task InitReaderAsync(FileViewModel? file, Stream fileStream) {
ParquetSerializer.UntypedResult fd = await ParquetSerializer.DeserializeAsync(
fileStream,
new ParquetOptions {
TreatByteArrayAsString = true
});

IList<Dictionary<string, object>>? data = null;
HasError = false;
ErrorMessage = null;
ErrorDetails = null;

try {
ParquetSerializer.UntypedResult fd = await ParquetSerializer.DeserializeAsync(
fileStream,
new ParquetOptions {
TreatByteArrayAsString = true
});
data = fd.Data;
} catch(Exception ex) {
HasError = true;
ErrorMessage = ex.Message;
ErrorDetails = ex.ToString();
}

Dispatcher.UIThread.Invoke(() => {
File = file;
Data = fd.Data;
Data = data;
});
}
}
39 changes: 26 additions & 13 deletions src/Parquet.Floor/Views/DataView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,36 @@
<vm:DataViewModel />
</Design.DataContext>

<DataGrid x:Name="grid"
AutoGenerateColumns="False"
CanUserSortColumns="True"
CanUserResizeColumns="True"
CanUserReorderColumns="True"
GridLinesVisibility="Horizontal"
IsReadOnly="True"
ItemsSource="{Binding Data}"
CellPointerPressed="DataGrid_CellPointerPressed">
<DataGrid.Columns>
<!--
<Grid>
<DataGrid x:Name="grid"
AutoGenerateColumns="False"
CanUserSortColumns="True"
CanUserResizeColumns="True"
CanUserReorderColumns="True"
GridLinesVisibility="Horizontal"
IsReadOnly="True"
ItemsSource="{Binding Data}"
CellPointerPressed="DataGrid_CellPointerPressed">
<DataGrid.Columns>
<!--
<DataGridTextColumn Header="First Name" Width="*"
Binding="{Binding [id]}"/>
<DataGridTextColumn Header="Last Name" Width="*"
Binding="{Binding [name]}" />
-->
</DataGrid.Columns>
</DataGrid>
</DataGrid.Columns>
</DataGrid>

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" IsVisible="{Binding HasError}">
<i:Icon Value="fa-solid fa-bomb" FontSize="30" />
<TextBlock Text="{Binding ErrorMessage}" HorizontalAlignment="Center"/>
<Expander Header="Details">
<ScrollViewer>
<TextBox AcceptsReturn="True" TextWrapping="Wrap" Text="{Binding ErrorDetails}" />
</ScrollViewer>
</Expander>
</StackPanel>

</Grid>

</UserControl>
17 changes: 9 additions & 8 deletions src/Parquet.Floor/Views/ErrorView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Parquet.Floor.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:i="https://github.com/projektanker/icons.avalonia"
x:Class="Parquet.Floor.Views.ErrorView"
x:DataType="vm:MainViewModel">
<Design.DataContext>
Expand All @@ -12,14 +13,14 @@
<vm:MainViewModel />
</Design.DataContext>

<Grid Classes="error">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="/Assets/icons/bat_dead.png"/>
<TextBlock Text="{Binding ErrorMessage}" HorizontalAlignment="Center" Classes="error" />
<TextBlock Text="details..." Classes="hyperlink" HorizontalAlignment="Center" IsVisible="{Binding !ShowErrorDetails}" PointerPressed="TextBlock_PointerPressed"/>
<ScrollViewer IsVisible="{Binding ShowErrorDetails}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<i:Icon Value="fa-solid fa-bomb" FontSize="30" />
<TextBlock Text="{Binding ErrorMessage}" HorizontalAlignment="Center"/>
<Expander Header="Details">
<ScrollViewer>
<TextBox AcceptsReturn="True" TextWrapping="Wrap" Text="{Binding ErrorDetails}" />
</ScrollViewer>
</StackPanel>
</Grid>
</Expander>
</StackPanel>

</UserControl>
8 changes: 0 additions & 8 deletions src/Parquet.Floor/Views/ErrorView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,4 @@ public partial class ErrorView : UserControl {
public ErrorView() {
InitializeComponent();
}

public MainViewModel? ViewModel => DataContext as MainViewModel;

private void TextBlock_PointerPressed(object? sender, Avalonia.Input.PointerPressedEventArgs e) {
if(ViewModel != null) {
ViewModel.ShowErrorDetails = true;
}
}
}
20 changes: 20 additions & 0 deletions src/Parquet.Floor/Views/Templates/DataViewCellTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ public static Control BuildValue(object? value, Field f, int depth, string? extr
return CreateNullTextBlock();

if(forceData || f.SchemaType == SchemaType.Data) {
if(f is DataField df && df.IsArray) {
var sp = new StackPanel {
Orientation = Orientation.Horizontal
};
foreach(object? entry in (IEnumerable)value) {
TextBlock ctrl = entry == null
? CreateNullTextBlock()
: CreateTextBlock(entry.ToString()!, extraClassName);
var border = new Border {
BorderThickness = new Thickness(1),
BorderBrush = Avalonia.Media.Brushes.Black,
Margin = new Thickness(2),
CornerRadius = new CornerRadius(2)
};
border.Child = ctrl;
sp.Children.Add(border);
}
return sp;
}

TextBlock tb = CreateTextBlock(value.ToString()!, extraClassName);
tb.HorizontalAlignment = GetAlignment(f);
return tb;
Expand Down
39 changes: 23 additions & 16 deletions src/Parquet.Floor/Views/Templates/DataViewHeaderTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Parquet.Schema;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Layout;
using Avalonia;
using Parquet.Floor.ViewModels;
using Avalonia.Platform;
using Avalonia.Media.Imaging;
using Parquet.File.Values.Primitives;

namespace Parquet.Floor.Views.Templates {
class DataViewHeaderTemplate : IDataTemplate {
Expand All @@ -21,7 +15,12 @@ public DataViewHeaderTemplate(Field field) {
}

private static bool IsNumeric(Type t) =>
t == typeof(short) || t == typeof(int) || t == typeof(long) || t == typeof(decimal);
t == typeof(short) || t == typeof(ushort) ||
t == typeof(int) || t == typeof(uint) ||
t == typeof(long) || t == typeof(ulong) ||
t == typeof(float) ||
t == typeof(decimal) ||
t == typeof(double);

private static bool IsByteArray(Type t) =>
t == typeof(byte[]);
Expand All @@ -36,16 +35,24 @@ private Control CreateIcon() {
case SchemaType.Data:
if(_field is DataField df) {
if(IsNumeric(df.ClrType)) {
name = "number";
name = "hashtag";
} else if(IsString(df.ClrType)) {
name = "string";
name = "comment";
} else if(IsByteArray(df.ClrType)) {
name = "bytearray";
name = "chart-simple";
} else if(df.ClrType == typeof(bool)) {
name = "square-check";
} else if(df.ClrType == typeof(DateTime)) {
name = "calendar";
} else if(df.ClrType == typeof(TimeSpan)) {
name = "clock";
} else if(df.ClrType == typeof(Interval)) {
name = "hourglass";
}
}
break;
case SchemaType.Struct:
name = "struct";
name = "folder-tree";
break;
case SchemaType.Map:
name = "map";
Expand All @@ -59,11 +66,11 @@ private Control CreateIcon() {
if(name == null)
return new Control();

var image = new Image {
Source = new Bitmap(AssetLoader.Open(new Uri($"avares://floor/Assets/icons/col/{name}.png")))
return new Projektanker.Icons.Avalonia.Icon {
Value = $"fa-solid fa-{name}",
FontSize = 12,
Margin = new Thickness(6, 0, 0, 6)
};
image.Classes.Add("dt-icon");
return image;

}

Expand Down
Loading
Loading